题目链接: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 ,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 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 ;
}

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

 

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. c#使用DocX添加多级标题

    博客转移到 http://jacean.github.io/ 继续分享编程经验 先上效果.可以生成多级标题,但是不能生成1,1.1,1.2这样的自动序列, 只是这样的效果. 实现方法是给Paragra ...

  2. 调用WCF Data Service的几点Tips

    使用Linq实现sql in statement的时候,用EF的时候可以通过Contains.Exists的方法实现.但是在使用WCF Data Service的context的时候,会报不支持该方法 ...

  3. 实现Win7远程桌面关机和重启

    通过远程桌面控制Win7系统时,菜单中没有关机和重启按钮, 1.方法1 关机 shutdown -s -t 0重启 shutdown -r -t 0 可以先打开运行框(Win+R键),输入上述命令即可 ...

  4. Java基本开发环境搭建(适合第一次使用)

    Java基本开发环境搭建(适合第一次使用) 编写人:cc 阿爸 2013-10-17 一.开发工具获取 1.开发工具包JDK l  下载地址: 到ORACLE公司官方网站(http://www.ora ...

  5. DevExpress后置代码中初始化SQL数据源的方法

    //初始化SQL数据源的提供者和连接字符串 函数 OK public virtual void InitSqlDataSource_ConStr(SqlDataSource sql_ds) { Con ...

  6. mysql外键设置(待测试)

    外键的定义语法:[CONSTRAINT symbol] FOREIGN KEY [id] (index_col_name, ...)    REFERENCES tbl_name (index_col ...

  7. 菜鸟学习Hibernate——配置Hibernate环境

    一.概念. Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库.既然学习Hibernate那么第 ...

  8. uninstall 11.2.0.3.0 grid & database in linux 5.7

    OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ...

  9. Android--从相册中选取照片并返回结果

    启动系统相册去选择图片 //从相册中选取的方法 private void selectPhoto(){ Intent intent = new Intent(Intent.ACTION_PICK); ...

  10. linux之mysqlimport的哪些变态事儿

    mysqlimport是MySQL导入数据的工具,高效易用. 但掌握不透彻就会有一些变态事情.mysqlimport --host='laswebapp.mdb.game.yy.com' --port ...