Codeforces Round #278 (Div. 2)
题目链接:http://codeforces.com/contest/488
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 ,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行。
#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 HP, a 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 ;
}
后续:感谢大牛提出宝贵的意见
Codeforces Round #278 (Div. 2)的更多相关文章
- 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 ...
- 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 ...
- 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/ ...
- CodeForces Round #278 (Div.2) (待续)
A 这么简单的题直接贴代码好了. #include <cstdio> #include <cmath> using namespace std; bool islucky(in ...
- Codeforces Round #278 (Div. 1)
A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang an ...
- codeforces 487a//Fight the Monster// Codeforces Round #278(Div. 1)
题意:打怪兽.可增加自己的属性,怎样在能打倒怪兽的情况下花费最少? 这题关键要找好二分的量.一开始我觉得,只要攻击到101,防御到100,就能必胜,于是我对自己的三个属性的和二分(0到201),内部三 ...
- 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 ...
- Codeforces Round #278 (Div. 1) D - Conveyor Belts 分块+dp
D - Conveyor Belts 思路:分块dp, 对于修改将对应的块再dp一次. #include<bits/stdc++.h> #define LL long long #defi ...
- Codeforces Round #278 (Div. 1) B - Strip dp+st表+单调队列
B - Strip 思路:简单dp,用st表+单调队列维护一下. #include<bits/stdc++.h> #define LL long long #define fi first ...
随机推荐
- [leetcode]_Minimum Depth of Binary Tree
第五道树题,10分钟之内一遍AC.做树题越来越有feel~ 题目:求一棵树从root结点到叶子结点的最短路径. 思路:仍然是递归.如果一个结点的左右子树任意一边为Null,该子树的minDepth应为 ...
- Silverlight中的主题设置
关于Theme,我的理解是和ASP.NET主题中的CSS是一个意思,当然,Sl中的样式更加的强大. 第一种方式: 1,装完Silverlight Tookit之后,在C:\Program Files\ ...
- project 2010 使用技巧
快捷键 设置任务子任务 ALT+SHIFT+向右方向键 1.工作时间设置 新建一个日历后,可以在 “项目 >> 项目信息 >> 日历” 中进行选择
- mysql开启全文索引功能
注意:全文检索模块需要mysql开启全文索引功能,开启方法:修改mysql配置文件:window服务器为my.ini,linux服务器为my.cnf,在 [mysqld] 后面加入一行“ft_min_ ...
- C# 平时碰见的问题【4】
1. 模糊查询 like的参数化写法 string keyword="value"; // 要模糊匹配的值 错误示范: sql: string strSql=" ...
- 如何让dapper支持oracle游标呢?
Dapper是一个轻型的ORM类.它有啥优点.缺点相信很多朋友都知道了,园里也有很多朋友都有相关介绍,这里就不多废话. 如果玩过Oracle都知道,存储过程基本都是通过游标返回数据的,但是dapper ...
- C#读取和写入配置文件
使用.Net2.0中的ConfigurationManager可以方便的实现对配置app.config的读取和写入. ConfigurationManager默认没有自动载入项目,使用前必须手动添加, ...
- hadoop2—namenode—HA原理详解
在hadoop1中NameNode存在一个单点故障问题,也就是说如果NameNode所在的机器发生故障,那么整个集群就将不可用(hadoop1中有个SecorndaryNameNode,但是它并不是N ...
- python 类属性和实例属性
class AAA(): aaa = 10 # 情形1 obj1 = AAA() obj2 = AAA() print obj1.aaa, obj2.aaa, AAA.aaa # 情形2 obj1.a ...
- JSTL实现分页
JSTL(JSP Standard Tag Library ,JSP标准标签库)是一个不断完善的开放源代码的JSP标签库,是由apache的jakarta小组来维护的.JSTL只能运行在支持JSP1. ...