hdu2831Plants VS Zombies (贪心)
来源:互联网 发布:男士衣服搭配软件 编辑:程序博客网 时间:2024/06/06 13:12
Plants VS Zombies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 623 Accepted Submission(s): 264
Special Judge
Problem Description
Plants VS Zombies is a popular game in the TJU ACM Team now. However, RoBa is not very good at this game, so he wants you to write a program to help him.
We take a simplified version of this game. There are N rows in your backyard, and there are N zombies want to walk through your yard to eat your brain, and exactly one zombie in each row. The only method to defense the zombies is to plant “peashooter” on the other side of the yard. However, you need T seconds to plant one peashooter. Once the peashooter is planted, it will begin to shoot at the zombies in its row. The zombies have different speed Vi and defense Di, which means that, the zombie in the i-th row need Vi second the walk though the yard, and the i-th zombie will be killed after Di second of shooting. Please note you can only plant one peashooter in each row.
Unfortunately, in some cases, for the zombies are too fast and/or too strong and/or your planting is too slow, you cannot kill all the zombies in time, so the zombies will eat your brains.
We take a simplified version of this game. There are N rows in your backyard, and there are N zombies want to walk through your yard to eat your brain, and exactly one zombie in each row. The only method to defense the zombies is to plant “peashooter” on the other side of the yard. However, you need T seconds to plant one peashooter. Once the peashooter is planted, it will begin to shoot at the zombies in its row. The zombies have different speed Vi and defense Di, which means that, the zombie in the i-th row need Vi second the walk though the yard, and the i-th zombie will be killed after Di second of shooting. Please note you can only plant one peashooter in each row.
Unfortunately, in some cases, for the zombies are too fast and/or too strong and/or your planting is too slow, you cannot kill all the zombies in time, so the zombies will eat your brains.
Input
There are several test cases in the input. The first line of each test case contains two integers N (1 <= N <= 100) and T, indicating the number of rows and the time for planting one peashooter. Then N lines follow, each of which contains two integers Vi and Di.
Output
Output one line for each test case. If you can kill all the zombies, output N numbers separated by a space, that is, a permutation of 1,2,…N, indicating the order of your planting. If you cannot defend your yard, output “The zombies eat your brains!” in one line.
Sample Input
3 1020 1040 1030 103 1020 1040 1130 10
Sample Output
1 3 2The zombies eat your brains!题目大意:在 n 列中种下豌豆射手来阻挡每行的僵尸,且已知豌豆是每 t 秒种一棵,第i列的僵尸进入院子需要 v[i]秒,杀死需要 d[i]秒。问能否阻挡所有僵尸进入院子,若能,打印出僵尸被消灭的列数的顺序。若否打印“The zombies eat your brains!”。解题思路:经典的贪心问题,由题意知,僵尸进入院子所需时间v[i]较小的,而杀死他所需时间d[i]较大的应先被消灭,v[i]较大,而d[i]较小的可以放到后面再消灭。即v[i]-d[i]的差值较小的那列应先种上豌豆,所以需要对v[i]-d[i]进行升序排列。同时,若k为消灭前i-1列僵尸所用时间,则当k+d[i]<=v[i]时,第i列僵尸才能被消灭,否则,第i列就不能被消灭。代码:#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{int v,d;int r;}ans[120];int cmp(node x,node y){return (x.v-x.d)<(y.v-y.d);}int main(){int n,t;while(scanf("%d%d",&n,&t)!=EOF){memset(ans,0,sizeof(ans));for(int i=1;i<=n;i++){scanf("%d%d",&ans[i].v,&ans[i].d);ans[i].r=i;}sort(ans+1,ans+n+1,cmp);int flag=1;int k=t;for(int i=1;i<=n;i++){if(ans[i].d+k<=ans[i].v){k+=t;}else{flag=0;break;}}if(flag){printf("%d",ans[1].r);for(int i=2;i<=n;i++) printf(" %d",ans[i].r);printf("\n"); }else printf("The zombies eat your brains!\n");}return 0;}
0 0
- hdu2831Plants VS Zombies (贪心)
- bnu_4060 Plants vs. Zombies
- BNU4060:Plants vs. Zombies
- toj4120.Zombies VS Plants
- TOJ 4120 Zombies VS Plants
- hdu 2831 plants VS zombies
- TOJ 3307.Plants VS Zombies
- 游戏推荐——Plants vs. Zombies
- hdu(2831)Plants VS Zombies
- UVA 12452 Plants vs. Zombies HD SP 树形dp(水
- Google Play 出现假的植物大战殭尸2( Plants vs. Zombies 2)
- SOJ4264 garlic and zombies
- sgu296:Sasha vs. Kate(贪心)
- NOJ 1127 Kill the Zombies
- 什么是僵死进程(Zombies)
- SGU 296 Sasha vs. Kate ( 贪心 )
- poj 1018 Communication System 枚举 VS 贪心
- CODE[VS] 1198【NOIP2012】 国王游戏(贪心
- swift2.0 UIImagePickerController 拍照 相册 录像
- 关于android的坐标及Scroll问题
- 循环队列
- unix time stamp(时间戳)和常规时间相互转换的C++代码
- archlinux 使用vnc登陆 raspberrypi2
- hdu2831Plants VS Zombies (贪心)
- 日经春秋 20151009
- 百度 在线编辑器ueditor1_4_3使用方法及配置
- Android开发菜鸟级入门2--尝试升级&绘图
- FTP文件传输协议两种方式的工作原理
- 数组和集合的相互转换
- 4. Firebug 调试 Js
- 本地主机ping上虚拟机的设置--hostonly方式
- 华为2013年机试题