题目链接: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. http://www.shanghaihaocong.com-WORDPRESS开发的企业主题站

    wordpress是世界上使用最多的php开源博客系统,功能强大,而且拥有众多的插件,可扩展性强. 最近,我也用它做了一个企业网站,欢迎浏览:http://www.shanghaihaocong.co ...

  2. 简单翻译和补充:1. GNU ARM Eclipse

    原文链接: GNU ARM Eclipse GNU 介绍: GNU 计划,又称革奴计划,是由RichardStallman在1983年9月27日公开发起的.它的目标是创建一套完全自由的操作系统.Ric ...

  3. [terry笔记]ora-00904 invalid identifier—同义词

    今天遇到一个问题,说起来也简单,但是困扰我半天. 升级数据库后,一个功能无法运行,在后台观察到其sql,发现sql中包含一个包执行不了,报错ora-00904 invalid identifier w ...

  4. 007-python基础-pyc是什么

    3.1 解释型语言和编译型语言 计算机是不能够识别高级语言的,所以当我们运行一个高级语言程序的时候,就需要一个"翻译机"来从事把高级语言转变成计算机能读懂的机器语言的过程.这个过程 ...

  5. flask学习

    安装环境: centos 6.3 python2.6 使用easy_install安装方式: [root@localhost ~]# easy_install flask 简单的hello from  ...

  6. python解析页面上json字段

    一般来说,当我们从一个网页上拿下来数据,就是一个字符串,比如: url_data = urllib2.urlopen(url).readline() 当我们这样得到页面数据,url_data是全部页面 ...

  7. python 核心编程第二版 课后习题 第11章

    11-3 函数.在这个练习中,我们将实现 max()和 min()内建函数. (a) 写分别带两个元素返回一个较大和较小元素,简单的 max2()核 min2()函数.他们应该可以用任意的 pytho ...

  8. Python学习教程(learning Python)--2.1 Python下自定义函数

    在Python里可以自定义函数,实现某特定功能,这里首先要区分一下函数的定义和函数的调用两个基本概念,初学者往往容易混淆. 函数的定义是指将一堆能实现特定功能的语句用一个函数名标识起来,而函数的调用则 ...

  9. ios开发笔记

    @IBDesignable  可在第二视图中实时预览 @IBInspectable 可编辑属性

  10. 关于HTML中,绝对定位,相对定位的理解...(学习HTML过程中的小记录)

    关于HTML中,绝对定位,相对定位的理解...(学习HTML过程中的小记录)   作者:王可利(Star·星星) HTML中 相对定位:position:relative; 绝对定位:position ...