题目链接: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。

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

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

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<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<cmath>
  6. #include<algorithm>
  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;//M
  19. int num2=atk_m-def_y;//Y
  20. if (num1> && num2<=) {printf("0\n");continue; }
  21. int minnum=;
  22. int mincnt=inf;
  23. int num= def_m-atk_y>= ? def_m-atk_y : ;
  24. for (int j=num ;j<= ;j++)///atk_y
  25. {
  26. num1=j+atk_y-def_m;
  27. if (num1<=) continue;
  28. int hh_m=hp_m;
  29. int time1=;
  30. time1=hh_m/num1;
  31. if (hh_m%num1) time1 ++ ;
  32. for (int i= ;i<= ;i++) { ///hp_y
  33. for (int k= ;k<= ;k++) {
  34. int hh_y=i+hp_y;
  35. num2=atk_m-def_y-k;
  36. if (num2<=)
  37. {
  38. if (mincnt>j*a+k*d)
  39. mincnt=j*a+k*d;
  40. continue;
  41. }
  42. int time2=;
  43. time2=hh_y/num2;
  44. if (hh_y%num2==) 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 ;
  58. }

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

 

Codeforces Round #278 (Div. 2)的更多相关文章

  1. Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)

    B. Candy Boxes Problem's Link:   http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. ana ...

  2. Codeforces Round #278 (Div. 1) B. Strip multiset维护DP

    B. Strip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/B De ...

  3. Codeforces Round #278 (Div. 1) A. Fight the Monster 暴力

    A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/ ...

  4. CodeForces Round #278 (Div.2) (待续)

    A 这么简单的题直接贴代码好了. #include <cstdio> #include <cmath> using namespace std; bool islucky(in ...

  5. Codeforces Round #278 (Div. 1)

    A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang an ...

  6. codeforces 487a//Fight the Monster// Codeforces Round #278(Div. 1)

    题意:打怪兽.可增加自己的属性,怎样在能打倒怪兽的情况下花费最少? 这题关键要找好二分的量.一开始我觉得,只要攻击到101,防御到100,就能必胜,于是我对自己的三个属性的和二分(0到201),内部三 ...

  7. Codeforces Round #278 (Div. 2) D. Strip 线段树优化dp

    D. Strip time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  8. Codeforces Round #278 (Div. 1) D - Conveyor Belts 分块+dp

    D - Conveyor Belts 思路:分块dp, 对于修改将对应的块再dp一次. #include<bits/stdc++.h> #define LL long long #defi ...

  9. Codeforces Round #278 (Div. 1) B - Strip dp+st表+单调队列

    B - Strip 思路:简单dp,用st表+单调队列维护一下. #include<bits/stdc++.h> #define LL long long #define fi first ...

随机推荐

  1. Filestream读取或写入文件

    using System.IO;//引用 System.IO namespace filestream { public partial class Form1 : Form { public For ...

  2. 工作中nginx配置文件的一些参数记录

    reset_timedout_connection on 告诉nginx关闭不响应的客户端连接.这将会释放那个客户端所占有的内存空间 tcp_nopush on 告诉nginx在一个数据包里发送许多个 ...

  3. 在Spark中使用Kryo序列化

    spark序列化  对于优化<网络性能>极为重要,将RDD以序列化格式来保存减少内存占用. spark.serializer=org.apache.spark.serializer.Jav ...

  4. [Linux]Nginx + Node.js + PM2 + MongoDb + (Memcached) Part I

    运行环境: 在本地的VirtualBox下运行的Ubuntu 14.04 LTS  0. 查看一下Server的IP地址 ifconfig 我的Server IP是192.168.0.108 1. 安 ...

  5. php 判断table 是否存在 根据返回值继续下一步的操作

    根据sql命令创建数据库或者数据表时候,判断库或者表是否存在比较重要. //要创建的表是否已经存在 function isHaveTable( $dbName,$tableN, $con)  //数据 ...

  6. leetCode刷题记录

    (1)Linked List Cycle Total Accepted: 13297 Total Submissions: 38411 Given a linked list, determine i ...

  7. Python学习教程(learning Python)--3.3 分支语句的条件表达式详解

    本节主要讨论分支语句的条件表达式问题. 在if或者if-else分支控制语句里由于都用到条件判断(表达式是真还是假),条件判断可以是一种关系运算也可以是布尔表达式. 本节将对if及if-else语句的 ...

  8. [Prism框架实用分享]如何在主程序中合理的弹出子窗体

    大家好 说起子窗体,大家都会想到ChildWindow,多熟悉的一个控件.不错,Sliverlight中已经提供了子窗体的具体实现,而在WPF中却没有这么好的事情(有的第三方控件商已经提供此控件).最 ...

  9. 对 cloudwu 简单的 cstring 进行简单解析

    题外话 以前也用C写过字符串,主要应用的领域是,大字符串,文件读取方面.写的很粗暴,用的凑合着.那时候看见云风前辈的一个开源的 cstring 串. 当时简单观摩了一下,觉得挺好的.也没细看.过了较长 ...

  10. AsyncTask和Handler两种异步方式的实现和区别比较

    1  AsyncTask实现的原理,和适用的优缺点 AsyncTask,是android提供的轻量级的异步类,可以直接继承AsyncTask,在类中实现异步操作,并提供接口反馈当前异步执行的程度(可以 ...