hdu(2831)Plants VS Zombies
来源:互联网 发布:js后退事件 编辑:程序博客网 时间:2024/06/10 21:26
本题是一个贪心题,关键在于思考如何排序才好;
这里应该用最多多余时间来排序,即:s[i].x=s[i].v-s[i].d-t;
在这里需要明白的几点是:
每行在开打之前都需要t时间来种植植物;所以排序要按上面的进行也就很好解释了;
此题最好用结构体来写,四个两都要在其中,因为排完序之后,v和d的顺序,也要按排完后比较;
在此,再比较判断时,t每次都要增加t,如果打死需要的时间和在此前总种植的时间之和小于度过总时间,则会吃到。。
#include"stdio.h"
#include"algorithm"
using namespace std;
struct point
{
int x,y,z,w;
}a[1000];
int cmp(point a,point b)
{
return a.x<b.x;
}
int main()
{
int m,n,i,t;
while(scanf("%d%d",&n,&t)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%d%d",&a[i].z,&a[i].w);
a[i].x=a[i].z-t-a[i].w;
a[i].y=i+1;
}
sort(a,a+n,cmp);
m=t;
for(i=0;i<n;i++)
{
if(a[i].z-t<a[i].w)
{
printf("The zombies eat your brains!\n");
break;
}
t+=m;
}
if(i==n)
{
for(i=0;i<n-1;i++)
printf("%d ",a[i].y);
printf("%d\n",a[i].y);
}
}
return 0;
}
- hdu(2831)Plants VS Zombies
- hdu 2831 plants VS zombies
- bnu_4060 Plants vs. Zombies
- BNU4060:Plants vs. Zombies
- toj4120.Zombies VS Plants
- TOJ 4120 Zombies VS Plants
- TOJ 3307.Plants VS Zombies
- 游戏推荐——Plants vs. Zombies
- UVA 12452 Plants vs. Zombies HD SP 树形dp(水
- Google Play 出现假的植物大战殭尸2( Plants vs. Zombies 2)
- hdu2831Plants VS Zombies (贪心)
- 关于Plants versus Zombies游戏中的Pogo stick玩具
- 什么是僵死进程(Zombies)
- garlic and zombies(模拟法)
- Codeforces Gym 101061 B RGB plants(矩阵快速幂)
- GYM 101061 B.RGB plants(dp+矩阵快速幂)
- SOJ4264 garlic and zombies
- 【Google Code Jam 2009 round2 problem D】Watering Plants (两圆交点求法详解)
- HDOJ 4578/2013年杭州邀请赛C题 - Transformation 线段树...比较蛋疼的维护PushDown
- 导致物理内存使用率高的原因以及解决办法【xiame】
- grub快速修复
- HDU1214--圆桌会议 HDU(90)
- android,获取北京时区时间
- hdu(2831)Plants VS Zombies
- UFOs
- 机器学习基础-概率论知识点
- Windows 开发之注册表操作-UAC
- 浅谈协方差矩阵
- C/S与B/S的区别
- for循环语句头的执行顺序
- Java的JAR包, EAR包 ,WAR包内部结构
- javascript.Math.ceil/floor