Codeforces Round #278 (Div. 2)

时间:2023-03-09 20:03:17
Codeforces Round #278 (Div. 2)

题目链接:http://codeforces.com/contest/488

A. Giga Tower

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.

题意:给出一个定义"lucky number":至少有一位上面是'8' 。现在给一个数a,求一个最小正数b,满足a+b之后是lucky number。

解法:暴力。因为题目要求一个数里面有一个数位上的数字为8就可以,所以不管a是不是luncky number,在枚举个位的时候一定会出现8。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=+;
int main()
{
int n;
while (scanf("%d",&n)!=EOF)
{
int num=n;
while ()
{
num++;
int flag=;
int j= num< ? -num : num;
while (j)
{
int k=j%;
if (k==) {flag=;break; }
j /= ;
}
if (flag) {printf("%d\n",num-n);break;}
}
}
return ;
}

B:Candy Boxes

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 ≤ x4) arithmetic mean is Codeforces Round #278 (Div. 2),median is Codeforces Round #278 (Div. 2) and range is x4 - x1. The 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)?

题意:一个集合x1,x2,x3,x4四个元素(x1<=x2<=x3<=x4),定义三个式子:mean=(x1+x2+x3+x4)/4,median=(x2+x3)/2,range=x4-x1。现在四个元素不完整,给出一部分,判断是否能求出满足条件的剩余部分。

解法:1:因为只有4个数,就直接想到了纯暴力,代码挫,写了近200行。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=+;
int main()
{
int n;
int an[];
while (scanf("%d",&n)!=EOF)
{
for (int i= ;i<=n ;i++) scanf("%d",&an[i]);
sort(an+,an+n+);
if (n==)
{
printf("YES\n");
printf("1\n1\n3\n3\n");continue;
}
if (n==)
{
int t=*an[];
printf("YES\n");
printf("%d\n%d\n%d\n",t/,t/*,t/*);
continue;
}
if (n==)
{
int flag=;
// 1 2
int t=*an[];
int bn[];
bn[]=an[],bn[]=*bn[];
bn[]=an[];
bn[]=*bn[]-bn[];
if (bn[]>=bn[] && bn[]>=bn[] && bn[]>=bn[] && bn[]<=)
{
flag=;
printf("YES\n");
printf("%d\n%d\n",bn[],bn[]);
continue;
}
// 1 3
t=*an[];
bn[]=an[];
bn[]=an[];
bn[]=*t-bn[];
bn[]=bn[]+t;
if (bn[]>=bn[] && bn[]>=bn[] && bn[]>=bn[] && bn[]<=)
{
flag=;
printf("YES\n");
printf("%d\n%d\n",bn[],bn[]);
continue;
}
// 1 4
t=*an[];
bn[]=an[];
bn[]=bn[]+t;
if (an[]==bn[])
{
bn[]=bn[];
bn[]=bn[];
if (bn[]>=bn[] && bn[]>=bn[] && bn[]>=bn[] && bn[]<=)
{
flag=;
printf("YES\n");
printf("%d\n%d\n",bn[],bn[]);
continue;
}
}
// 2 3
double cn[];
double tt=(double)(an[]+an[])/;
cn[]=an[] ;cn[]=an[] ;
cn[]=tt/2.0;
cn[]=1.5*tt;
if (cn[]>=cn[] && cn[]>=cn[] && cn[]>=cn[] && cn[]<=)
{
flag=;
printf("YES\n");
printf("%.0lf\n%.0lf\n",cn[],cn[]);
continue;
}
// 2 4
cn[]=an[];
cn[]=an[];
tt=2.0*cn[]/3.0;
cn[]=tt/2.0;
cn[]=2.0*tt-cn[];
if (cn[]>=cn[] && cn[]>=cn[] && cn[]>=cn[] && cn[]<=)
{
flag=;
printf("YES\n");
printf("%.0lf\n%.0lf\n",cn[],cn[]);
continue;
}
// 3 4
cn[]=an[];
cn[]=an[];
tt=2.0*cn[]/3.0;
cn[]=tt/2.0;
cn[]=2.0*tt-cn[];
if (cn[]>=cn[] && cn[]>=cn[] && cn[]>=cn[] && cn[]<=)
{
flag=;
printf("YES\n");
printf("%.0lf\n%.0lf\n",cn[],cn[]);
continue;
}
if (!flag) printf("NO\n");
}
if (n==)
{
// 1 2 3
double cn[];
int flag=;
cn[]=an[] ;cn[]=an[] ;cn[]=an[] ;
double tt=2.0*cn[];
cn[]=1.5*tt;
if (cn[]+cn[]==2.0*tt)
{
if (cn[]>=cn[] && cn[]>=cn[] && cn[]>=cn[] && cn[]<=)
{
flag=;
printf("YES\n");
printf("%.0lf\n",cn[]);
continue;
}
}
// 1 2 4
cn[]=an[] ;cn[]=an[] ;cn[]=an[];
tt=2.0*cn[];
cn[]=2.0*tt-cn[];
if (2.0*cn[]==3.0*tt)
{
if (cn[]>=cn[] && cn[]>=cn[] && cn[]>=cn[] && cn[]<=)
{
flag=;
printf("YES\n");
printf("%.0lf\n",cn[]);
continue;
}
}
// 2 3 4
cn[]=an[] ;cn[]=an[] ;cn[]=an[] ;
tt=(cn[]+cn[])/2.0;
cn[]=tt/2.0;
if (cn[]*2.0==3.0*tt)
{
if (cn[]>=cn[] && cn[]>=cn[] && cn[]>=cn[] && cn[]<=)
{
flag=;
printf("YES\n");
printf("%.0lf\n",cn[]);
continue;
}
}
// 1 3 4
cn[]=an[] ;cn[]=an[] ;cn[]=an[] ;
tt=2.0*cn[];
cn[]=2.0*tt-cn[];
if (2.0*cn[]==3.0*tt)
{
if (cn[]>=cn[] && cn[]>=cn[] && cn[]>=cn[] && cn[]<=)
{
flag=;
printf("YES\n");
printf("%.0lf\n",cn[]);
continue;
}
}
if (!flag) printf("NO\n");
}
if (n==)
{
double tt=2.0*an[];
int flag=;
if (an[]+an[]==2.0*tt && 2.0*an[]==3.0*tt)
{
if (an[]>=an[] && an[]>=an[] && an[]>=an[] && an[]<=)
{
flag=;
printf("YES\n");
continue;
}
}
if (!flag) printf("NO\n");
}
}
return ;
}

C:Fight the Monster

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.

题意:两个人Y和M,每个人有三个值,Y : hp_y , atk_y , def_y ; M :  hp_m , atk_m , def_m 。接下来每一秒里M的hp_m值减少max(0,atk_y-def_m),Y的hp_y值减少max(0,atk_m-def_y),如果hp_m<=0 && hp_y>0 ,那么Y win 。现在Y还可以在商店购买hp_y , atk_y , def_y 的值,单价分别为h , a , d。询问Y 赢的条件下,花最少的钱。

解法:1:思路不是很清晰,就直接三重循环暴力枚举了。想不到证明枚举的上限,so 一直在改上限,然后提交,,改上限,然后提交的死循环中

   2:看到CF上面有人推出了公式什么的,还在学习中。。。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
int main()
{
int hp_y,atk_y,def_y;
int hp_m,atk_m,def_m;
int h,a,d;
while (scanf("%d%d%d",&hp_y,&atk_y,&def_y)!=EOF)
{
scanf("%d%d%d",&hp_m,&atk_m,&def_m);
scanf("%d%d%d",&h,&a,&d);
int num1=atk_y-def_m;//M
int num2=atk_m-def_y;//Y
if (num1> && num2<=) {printf("0\n");continue; }
int minnum=;
int mincnt=inf;
int num= def_m-atk_y>= ? def_m-atk_y : ;
for (int j=num ;j<= ;j++)///atk_y
{
num1=j+atk_y-def_m;
if (num1<=) continue;
int hh_m=hp_m;
int time1=;
time1=hh_m/num1;
if (hh_m%num1) time1 ++ ;
for (int i= ;i<= ;i++) { ///hp_y
for (int k= ;k<= ;k++) {
int hh_y=i+hp_y;
num2=atk_m-def_y-k;
if (num2<=)
{
if (mincnt>j*a+k*d)
mincnt=j*a+k*d;
continue;
}
int time2=;
time2=hh_y/num2;
if (hh_y%num2==) time2--;
if (time2>=time1)
{
if (mincnt>i*h+j*a+d*k)
{
mincnt=i*h+j*a+k*d;
}
}
}
}
}
printf("%d\n",mincnt);
}
return ;
}

后续:感谢大牛提出宝贵的意见