TOJ 3307.Plants VS Zombies
2016-12-11 02:11
232 查看
题目链接:http://acm.tju.edu.cn/toj/showp3307.html
3307. Plants VS Zombies
Time Limit: 1.0 Seconds Memory Limit: 65536K Special Judge
Total Runs: 376 Accepted Runs: 207
Plants VS ZombiesTM 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.
which contains two integers Vi and Di.
your brains!" in one line.
Hint: For the first case, you should plant a peashooter in the first row, then plant in the third row, then the second row. Then all the zombies are killed just in time. For the second
case, however, the zombie in second row is a little stronger, so you cannot kill all of them.
Author: HE, Liang
Note: Special judge problem, you may get "Wrong Answer" when output in wrong format.
Source: Multi-School
Training Contest - TOJ Site #2
Submit List
Runs Forum Statistics
水题,排序在算一下就好;
#include<stdio.h>
#include<algorithm>
using namespace std;
struct plant{
int id;
int value;
}plants[101];
bool cmp(plant a, plant b){
return a.value<b.value;
}
int main(){
int n,t,v,d;
while(~scanf("%d%d",&n,&t)){
for(int i=0;i<n;i++){
scanf("%d%d",&v,&d);
plants[i].id = i + 1;
plants[i].value = v-d;
}
sort(plants,plants+n,cmp);
int time=0;
bool isEat = false;
for(int i=1;i<=n;i++){
if(time+t>plants[i-1].value){
printf("The zombies eat your brains!\n");
isEat = true;
break;
}
time+=t;
}
if(!isEat){
for(int i=0;i<n-1;i++)
printf("%d ",plants[i].id);
printf("%d\n",plants[n-1].id);
}
}
}
3307. Plants VS Zombies
Time Limit: 1.0 Seconds Memory Limit: 65536K Special Judge
Total Runs: 376 Accepted Runs: 207
Plants VS ZombiesTM 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.
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 ofwhich 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 eatyour brains!" in one line.
Sample Input
3 10 20 10 40 10 30 10 3 10 20 10 40 11 30 10
Sample Output
1 3 2 The zombies eat your brains!
Hint: For the first case, you should plant a peashooter in the first row, then plant in the third row, then the second row. Then all the zombies are killed just in time. For the second
case, however, the zombie in second row is a little stronger, so you cannot kill all of them.
Author: HE, Liang
Note: Special judge problem, you may get "Wrong Answer" when output in wrong format.
Source: Multi-School
Training Contest - TOJ Site #2
Submit List
Runs Forum Statistics
水题,排序在算一下就好;
#include<stdio.h>
#include<algorithm>
using namespace std;
struct plant{
int id;
int value;
}plants[101];
bool cmp(plant a, plant b){
return a.value<b.value;
}
int main(){
int n,t,v,d;
while(~scanf("%d%d",&n,&t)){
for(int i=0;i<n;i++){
scanf("%d%d",&v,&d);
plants[i].id = i + 1;
plants[i].value = v-d;
}
sort(plants,plants+n,cmp);
int time=0;
bool isEat = false;
for(int i=1;i<=n;i++){
if(time+t>plants[i-1].value){
printf("The zombies eat your brains!\n");
isEat = true;
break;
}
time+=t;
}
if(!isEat){
for(int i=0;i<n-1;i++)
printf("%d ",plants[i].id);
printf("%d\n",plants[n-1].id);
}
}
}
相关文章推荐
- bnu_4060 Plants vs. Zombies
- hdu(2831)Plants VS Zombies
- BNU4060:Plants vs. Zombies
- 【本月最佳游戏】《植物大战僵尸(Plants vs. Zombies)》[29M][EN]
- 游戏推荐——Plants vs. Zombies
- bnu_4060 Plants vs. Zombies
- Google Play 出现假的植物大战殭尸2( Plants vs. Zombies 2)
- hdu 2831 plants VS zombies
- UVA 12452 Plants vs. Zombies HD SP 树形dp(水
- toj4120.Zombies VS Plants
- TOJ 2674 Java Vs C++ 字符串处理
- TOJ 2674. Java vs C++
- 补疑(编译错误VS运行错误)
- Table Variable vs. Temp Table Summary
- vs 主题
- VS 快捷键大全(转)
- 2014Q3至2015Q2高通产品规划图 VS MTK产品规划图
- [C++]VS与第三方工具下载
- VS代码自动对齐
- VS2015使用小技巧 打开VS015自带的ildasm反编译器