博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #278 (Div. 2)
阅读量:5024 次
发布时间:2019-06-12

本文共 9133 字,大约阅读时间需要 30 分钟。

题目链接:

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。

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #define inf 0x7fffffff 8 using namespace std; 9 const int maxn=100+10;10 int main()11 {12 int n;13 while (scanf("%d",&n)!=EOF)14 {15 int num=n;16 while (1)17 {18 num++;19 int flag=0;20 int j= num<0 ? -num : num;21 while (j)22 {23 int k=j%10;24 if (k==8) {flag=1;break; }25 j /= 10;26 }27 if (flag) {printf("%d\n",num-n);break;}28 }29 }30 return 0;31 }
View Code

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 ,median is  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行。

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #define inf 0x7fffffff 8 using namespace std; 9 const int maxn=100+10; 10 int main() 11 { 12 int n; 13 int an[5]; 14 while (scanf("%d",&n)!=EOF) 15 { 16 for (int i=1 ;i<=n ;i++) scanf("%d",&an[i]); 17 sort(an+1,an+n+1); 18 if (n==0) 19 { 20 printf("YES\n"); 21 printf("1\n1\n3\n3\n");continue; 22 } 23 if (n==1) 24 { 25 int t=2*an[1]; 26 printf("YES\n"); 27 printf("%d\n%d\n%d\n",t/2,t/2*3,t/2*3); 28 continue; 29 } 30 if (n==2) 31 { 32 int flag=0; 33 // 1 2 34 int t=2*an[1]; 35 int bn[5]; 36 bn[1]=an[1],bn[4]=3*bn[1]; 37 bn[2]=an[2]; 38 bn[3]=4*bn[1]-bn[2]; 39 if (bn[2]>=bn[1] && bn[3]>=bn[2] && bn[4]>=bn[3] && bn[4]<=1000000) 40 { 41 flag=1; 42 printf("YES\n"); 43 printf("%d\n%d\n",bn[3],bn[4]); 44 continue; 45 } 46 // 1 3 47 t=2*an[1]; 48 bn[1]=an[1]; 49 bn[3]=an[2]; 50 bn[2]=2*t-bn[3]; 51 bn[4]=bn[1]+t; 52 if (bn[2]>=bn[1] && bn[3]>=bn[2] && bn[4]>=bn[3] && bn[4]<=1000000) 53 { 54 flag=1; 55 printf("YES\n"); 56 printf("%d\n%d\n",bn[2],bn[4]); 57 continue; 58 } 59 // 1 4 60 t=2*an[1]; 61 bn[1]=an[1]; 62 bn[4]=bn[1]+t; 63 if (an[2]==bn[4]) 64 { 65 bn[2]=bn[1]; 66 bn[3]=bn[4]; 67 if (bn[2]>=bn[1] && bn[3]>=bn[2] && bn[4]>=bn[3] && bn[4]<=1000000) 68 { 69 flag=1; 70 printf("YES\n"); 71 printf("%d\n%d\n",bn[2],bn[3]); 72 continue; 73 } 74 } 75 // 2 3 76 double cn[5]; 77 double tt=(double)(an[1]+an[2])/2; 78 cn[2]=an[1] ;cn[3]=an[2] ; 79 cn[1]=tt/2.0; 80 cn[4]=1.5*tt; 81 if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000) 82 { 83 flag=1; 84 printf("YES\n"); 85 printf("%.0lf\n%.0lf\n",cn[3],cn[4]); 86 continue; 87 } 88 // 2 4 89 cn[4]=an[2]; 90 cn[2]=an[1]; 91 tt=2.0*cn[4]/3.0; 92 cn[1]=tt/2.0; 93 cn[3]=2.0*tt-cn[2]; 94 if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000) 95 { 96 flag=1; 97 printf("YES\n"); 98 printf("%.0lf\n%.0lf\n",cn[1],cn[3]); 99 continue;100 }101 // 3 4102 cn[3]=an[1];103 cn[4]=an[2];104 tt=2.0*cn[4]/3.0;105 cn[1]=tt/2.0;106 cn[2]=2.0*tt-cn[3];107 if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000)108 {109 flag=1;110 printf("YES\n");111 printf("%.0lf\n%.0lf\n",cn[1],cn[2]);112 continue;113 }114 if (!flag) printf("NO\n");115 }116 if (n==3)117 {118 // 1 2 3119 double cn[5];120 int flag=0;121 cn[1]=an[1] ;cn[2]=an[2] ;cn[3]=an[3] ;122 double tt=2.0*cn[1];123 cn[4]=1.5*tt;124 if (cn[2]+cn[3]==2.0*tt)125 {126 if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000)127 {128 flag=1;129 printf("YES\n");130 printf("%.0lf\n",cn[4]);131 continue;132 }133 }134 // 1 2 4135 cn[1]=an[1] ;cn[2]=an[2] ;cn[4]=an[3];136 tt=2.0*cn[1];137 cn[3]=2.0*tt-cn[2];138 if (2.0*cn[4]==3.0*tt)139 {140 if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000)141 {142 flag=1;143 printf("YES\n");144 printf("%.0lf\n",cn[3]);145 continue;146 }147 }148 // 2 3 4149 cn[2]=an[1] ;cn[3]=an[2] ;cn[4]=an[3] ;150 tt=(cn[2]+cn[3])/2.0;151 cn[1]=tt/2.0;152 if (cn[4]*2.0==3.0*tt)153 {154 if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000)155 {156 flag=1;157 printf("YES\n");158 printf("%.0lf\n",cn[1]);159 continue;160 }161 }162 // 1 3 4163 cn[1]=an[1] ;cn[3]=an[2] ;cn[4]=an[3] ;164 tt=2.0*cn[1];165 cn[2]=2.0*tt-cn[3];166 if (2.0*cn[4]==3.0*tt)167 {168 if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000)169 {170 flag=1;171 printf("YES\n");172 printf("%.0lf\n",cn[2]);173 continue;174 }175 }176 if (!flag) printf("NO\n");177 }178 if (n==4)179 {180 double tt=2.0*an[1];181 int flag=0;182 if (an[2]+an[3]==2.0*tt && 2.0*an[4]==3.0*tt)183 {184 if (an[2]>=an[1] && an[3]>=an[2] && an[4]>=an[3] && an[4]<=1000000)185 {186 flag=1;187 printf("YES\n");188 continue;189 }190 }191 if (!flag) printf("NO\n");192 }193 }194 return 0;195 }
View Code

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上面有人推出了公式什么的,还在学习中。。。

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #define inf 0x7fffffff 8 using namespace std; 9 int main()10 {11 int hp_y,atk_y,def_y;12 int hp_m,atk_m,def_m;13 int h,a,d;14 while (scanf("%d%d%d",&hp_y,&atk_y,&def_y)!=EOF)15 {16 scanf("%d%d%d",&hp_m,&atk_m,&def_m);17 scanf("%d%d%d",&h,&a,&d);18 int num1=atk_y-def_m;//M19 int num2=atk_m-def_y;//Y20 if (num1>0 && num2<=0) {printf("0\n");continue; }21 int minnum=0;22 int mincnt=inf;23 int num= def_m-atk_y>=0 ? def_m-atk_y : 0 ;24 for (int j=num ;j<=500 ;j++)///atk_y25 {26 num1=j+atk_y-def_m;27 if (num1<=0) continue;28 int hh_m=hp_m;29 int time1=0;30 time1=hh_m/num1;31 if (hh_m%num1) time1 ++ ;32 for (int i=0 ;i<=1000 ;i++) { ///hp_y33 for (int k=0 ;k<=500 ;k++) {34 int hh_y=i+hp_y;35 num2=atk_m-def_y-k;36 if (num2<=0)37 {38 if (mincnt>j*a+k*d)39 mincnt=j*a+k*d;40 continue;41 }42 int time2=0;43 time2=hh_y/num2;44 if (hh_y%num2==0) time2--;45 if (time2>=time1)46 {47 if (mincnt>i*h+j*a+d*k)48 {49 mincnt=i*h+j*a+k*d;50 }51 }52 }53 }54 }55 printf("%d\n",mincnt);56 }57 return 0;58 }
View Code

 

 

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

 

转载于:https://www.cnblogs.com/huangxf/p/4115322.html

你可能感兴趣的文章
傅里叶级数与积分方程
查看>>
软工作业3:用户体验分析——以“南通大学教务管理系统微信公众号”为例
查看>>
Css:背景色透明,内容不透明之终极方法!兼容所有浏览器
查看>>
我们前端跟后端是怎么合作的
查看>>
mysql存储过程
查看>>
洛谷P2556 [AHOI2002] 黑白图像压缩 [模拟]
查看>>
letecode [136] - Single Number
查看>>
linux下设置固定IP的方法
查看>>
VMware虚拟机下Linux系统的全屏显示
查看>>
net core体系-web应用程序-4asp.net core2.0 项目实战(任务管理系统)-2项目搭建
查看>>
高效的jQuery
查看>>
ubuntu 16.04 (软件应用)-输入法
查看>>
windos7修复引导扇区
查看>>
Leetcode总结之Backtracking
查看>>
Android开发学习之路-图片颜色获取器开发(1)
查看>>
StackExchange.Redis 官方文档(一) Basics
查看>>
nupkg 之破解 nodejs+electron-packager 打包exe的解包
查看>>
Objective-C 使用 C++类
查看>>
浅谈之高级查询over(partition by)
查看>>
Notes: CRM Analytics–BI from a CRM perspective (2)
查看>>