第二十二次codeforces竞技结束 #278 Div 2

这次的题目略可怕,只出了2道题就成了46名,直接加了161分进入了紫名……


Codeforces Hot News!

Wow! Coder  CST14-okcd00 competed in Codeforces Round #278 (Div. 2) and gained +161 rating points taking place 46


A. Giga Tower

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from  - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor  - 1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.

In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8 888 888 888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,  - 180, 808 are all lucky while42,  - 10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).

Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will arrive at a floor with a lucky number.

Input

The only line of input contains an integer a ( - 109 ≤ a ≤ 109).

Output

Print the minimum b in a line.

Sample test(s)
input
179
output
1
input
-1
output
9
input
18
output
10
Note

For the first sample, he has to arrive at the floor numbered 180.

For the second sample, he will arrive at 8.

Note that b should be positive, so the answer for the third sample is 10, not 0.



题意是有着一座顶天入地的塔,我现在在其中的一层,问向上爬最少几层就可以到一个含有数字8的楼层

鉴于最多走10层就能变成个位数为8,so……为何不枚举?

需要注意的是楼层可以为负数不要直接简单相加弄错了哦~


Code:

#include <cmath> 
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))

bool cmp(const int a, const int b)
{
	return a > b;
}

bool judge(ll n)
{
	ll nn=abs(n);
	while(nn)
	{
		int now=nn%10;
		if(now==8)return true;
		else nn/=10;
	}
	return false;
}

int main()
{
	ll n;	cin>>n;
	for(ll i=1;;i++)
	{
		if(judge(n+i))
		{
			printf("%d",i);
			return 0;
		} 
	}
	return 0;
}

B. Candy Boxes

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {x1, x2, x3, x4} (x1 ≤ x2 ≤ x3 ≤ x4arithmetic mean is median is  and range is x4 - x1The arithmetic mean and median are not necessary integer. It is well-known that if those three numbers are same, boxes will create a "debugging field" and codes in the field will have no bugs.

For example, 1, 1, 3, 3 is the example of 4 numbers meeting the condition because their mean, median and range are all equal to 2.

Jeff has 4 special boxes of candies. However, something bad has happened! Some of the boxes could have been lost and now there are only n (0 ≤ n ≤ 4) boxes remaining. The i-th remaining box contains ai candies.

Now Jeff wants to know: is there a possible way to find the number of candies of the 4 - n missing boxes, meeting the condition above (the mean, median and range are equal)?

Input

The first line of input contains an only integer n (0 ≤ n ≤ 4).

The next n lines contain integers ai, denoting the number of candies in the i-th box (1 ≤ ai ≤ 500).

Output

In the first output line, print "YES" if a solution exists, or print "NO" if there is no solution.

If a solution exists, you should output 4 - n more lines, each line containing an integer b, denoting the number of candies in a missing box.

All your numbers b must satisfy inequality 1 ≤ b ≤ 106. It is guaranteed that if there exists a positive integer solution, you can always find such b's meeting the condition. If there are multiple answers, you are allowed to print any of them.

Given numbers ai may follow in any order in the input, not necessary in non-decreasing.

ai may have stood at any positions in the original set, not necessary on lowest n first positions.

Sample test(s)
input
2
1
1
output
YES
3
3
input
3
1
1
1
output
NO
input
4
1
2
2
3
output
YES
Note

For the first sample, the numbers of candies in 4 boxes can be 1, 1, 3, 3. The arithmetic mean, the median and the range of them are all2.

For the second sample, it's impossible to find the missing number of candies.

In the third example no box has been lost and numbers satisfy the condition.

You may output b in any order.


有四盒糖,糖的数量满足以下条件:

四盒糖的平均数和中位数相等,这个数值同时等于最大值和最小值的差。

我们优化一下,就是如果按照从小到大排序ABCD,那么A+D=B+C,2D-2A=B+C 故D=3A

好了这题成了4个盒子,其中一个为另一个的三倍,剩下俩的和等于这俩的和即可。

题目问:我现在只知道其中n个盒子(0~4)里的糖数,有没有可能满足上述条件,有的话输出糖数。

于是分情况讨论咯~ 

0)什么,你让我随便写? 1223

1)有一个了,A范围在0-500,b的范围不大于1e6……那果断乘三得到D咯 AADD

2)有俩了,那得看看,两个数相同的话直接AADD,不相同的话只要大的不超过小的数的三倍,那大的就是B(也可以是C,无妨),小的是A,然后D=3A,C=3A+A-B

3)都给了仨了那就看看剩下的是谁呗:

如果给的数有一个是另一个的三倍,剩下的那个只要在这俩之间就行,C=A+D-B

如果没有三倍关系那说明是ABC或者BCD组合,我们把最小数乘三吧(反正范围大)

4)四个都有了直接算看看是否满足条件咯~


Code:

#include <cmath> 
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
int a[5]={0};
const int limit=1000000;
bool cmp(const int a, const int b)
{
	return a > b;
}


int main()
{
	int n;	cin>>n;
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	if(n==0) printf("YES\n1\n1\n3\n3\n");
	else if(n==1)
	{
		printf("YES\n%d\n%d\n%d\n",a[0]*2,a[0]*2,a[0]*3);
	}
	else if(n==2)
	{
		sort(a,a+2);
		if(a[0]==a[1] && a[0]*3<=limit) printf("YES\n%d\n%d\n",a[0]*3,a[0]*3);
		else if(a[0]==a[1] && a[0]%3==0) printf("YES\n%d\n%d\n",a[0]/3,a[0]/3);
		else
		{
			if(a[1]%a[0]==0 && a[1]/a[0]==3) printf("YES\n%d\n%d\n",a[0],a[1]);
			else if(a[1]/a[0]<3 && a[0]*3<=limit) printf("YES\n%d\n%d\n",a[0]*3,a[0]*3+a[0]-a[1]);
			else printf("NO\n"); //nonsence, ignore it
		}
		
	} 
	else if(n==3)
	{
		sort(a,a+3);
		if(a[2]%a[0]==0 && a[2]/a[0]==3) printf("YES\n%d\n",a[2]-a[1]+a[0]);
		else 
		{
			int rest1=a[2]+a[1]-a[0];	//a_4
			int rest2=a[0]+a[1]-a[2];	//a_1
			if(rest1%a[0]==0 && rest1/a[0]==3 && rest1<=limit) printf("YES\n%d\n",rest1);
			else if(a[2]%rest2==0 && a[2]/rest2==3 && rest2<=limit) printf("YES\n%d\n",rest2);
			else printf("NO\n");
		}
		
	}
	else if(n==4)
	{
		sort(a,a+4);
		if(a[0]+a[3]==a[1]+a[2] && a[3]-a[0]==(a[1]+a[2])/2 && (a[1]+a[2])%2==0 ) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


C. Fight the Monster

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A monster is attacking the Cyberland!

Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF).

During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases bymax(0, ATKM - DEFY), where index Y denotes Master Yang and index M denotes monster. Both decreases happen simultaneously Once monster's HP ≤ 0 and the same time Master Yang's HP > 0, Master Yang wins.

Master Yang can buy attributes from the magic shop of Cyberland: h bitcoins per HPa bitcoins per ATK, and d bitcoins per DEF.

Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win.

Input

The first line contains three integers HPY, ATKY, DEFY, separated by a space, denoting the initial HPATK and DEF of Master Yang.

The second line contains three integers HPM, ATKM, DEFM, separated by a space, denoting the HPATK and DEF of the monster.

The third line contains three integers h, a, d, separated by a space, denoting the price of HPATK and DEF.

All numbers in input are integer and lie between 1 and 100 inclusively.

Output

The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win.

Sample test(s)
input
1 2 1
1 100 1
1 100 100
output
99
input
100 100 100
1 1 1
1 1 1
output
0
Note

For the first sample, prices for ATK and DEF are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left.

For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything.



数据范围都这么少了不模拟枚举不开心

Code:

#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int hy, ay, dy, hm, am, dm, h, a, d, ans = 1e9, i, j;
    
    scanf("%d %d %d", &hy, &ay, &dy);
    scanf("%d %d %d", &hm, &am, &dm);
    scanf("%d %d %d", &h, &a, &d);
    
    for (i = 0; i <= 200; i++) {
        for (j = 0; j <= 100; j++) {
            int x = max(0, ay + i - dm);
            int y = max(0, am - dy - j);
            int z, t;
            
            if (x == 0) continue;
            t = (hm + x - 1) / x;
            z = max(0, y * t + 1 - hy);
            ans = min(ans, i * a + j * d + z * h);
        }
    }
    
    printf("%d\n", ans);
    
    return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖果天王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值