题目链接: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. vue.js笔记

    一.v-bind 缩写 <!-- 完整语法 --> <a v-bind:href="url"></a> <!-- 缩写 --> &l ...

  2. Linux基础知识-文件管理

    Linux目录与路径 cd:切换目录 例如:cd ~willhua,则回到用户willhua的主文件夹  cd ~或者cd,则表示回到自己的的主文件夹  cd -,则表示回到上个目录 pwd:显示目前 ...

  3. 用js读、写、删除Cookie

    //已经验证过 // JavaScript Document //使用说明:  //设置缓存:setCookie("name",value); //获取缓存:var name=ge ...

  4. android 特效UI实现

    弧形菜单 https://github.com/daCapricorn/ArcMenu

  5. 做个伪IE浏览器?!【来自官网】

    原文:docwiki.embarcadero.com/RADStudio/Seattle/en/Building_a_VCL_Forms_Web_Browser_Application 选择File ...

  6. 学习simple.data之进阶篇

    一.结果排序 -OrderBy(升序) -OrderByDescending(降序) db.Product.All().OrderByFactoryName(); db.Product.All().O ...

  7. 菜鸟学习Struts——Scope属性

    一.概念. 在Action映射配置中,Scope属性可以取值为:request或session.Scope属性表示:Struts框架在将     ActionForm对象(与目标Action匹配的Ac ...

  8. git的工作流程(分支合并)

    git支持很多种工作流程,我们采用的一般是这样,远程创建一个主分支,本地每人创建功能分支,日常工作流程如下: 去自己的工作分支$ git checkout work 工作.... 提交工作分支的修改$ ...

  9. ubuntu crontab 定时备份postgres数据库并上传ftp服务器

    最近公司要求备份数据库,所以就查了比较作的资料.废话不多说,入正题. 目的:定期备份ubuntu下的postgres数据库,打包上传到指定ftp服务器. 经过查找资料,解决方法: ①编写备份数据库.打 ...

  10. CentOS6.4上搭建hadoop-2.4.0集群

    公司Commerce Cloud平台上提供申请主机的服务.昨天试了下,申请了3台机器,搭了个hadoop环境.以下是机器的一些配置: emi-centos-6.4-x86_64medium | 6GB ...