Hdu3640-I, zombie(模拟+二分)
To simplify the problem ,we provide only one kind of Zombies : normal Zombies with 50 hp each. The map contains one row only, and we provide two kinds of plants : Peashooter (with 10hp) and Potato Mine. The operating steps of every second are as below(Warning: make sure your program strictly follow the order of these steps):1.Put some or none zombies in the right-most grid one by one. (In the right grid of the right-most plant at beginning). 2.Judge every survived zombie, whether he's standing on a grid with a Peashooter. 2.1.If it's true, he attacks the Peashooter in his grid, and the Peashooter decreases 1 hp. The Peashooter's hp may be negative at that moment, but it's still alive! 2.2.If it's false, he moves left for one grid. 3.If there are still some zombies in the map, every survived Peashooter will shoot a pea to the zombie who was put earliest. (the zombie's hp decreases 1 hp for each pea, the zombie's hp can be negative at that moment, but it's still alive!) 4.If there are zombies in the grids where Potato Mine stands , then the Potato Mine explodes , all the zombies' hp in this grid become 0. 5.The plants and zombies with non-positive hp disappear(until now they are dead).
Now, given the map, you are to tell me how many zombies are needed at least, in order to eat the brain in the left-most?
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iterator>
#include<stack>
using namespace std;
const int maxn=;
char S[maxn];
int L,Pnum,Mnum,step;
void init()
{
L=strlen(S)-;
Pnum=Mnum=; //豌豆射手与土豆的个数
for(int i=;i<=L;i++)
if(S[i]=='P') Pnum++;
else Mnum++;
}
bool judge(int totpnum,int pnum,int znum)
{
int nowstep=step;
int P_hp=,Z_hp=; //豌豆射手和僵尸的hp
while(pnum>&&znum>)
{
if(nowstep>){ nowstep--; Z_hp-=totpnum; } //没走到豌豆射手处
else{ P_hp-=znum; Z_hp-=totpnum; } //走到了两个都要受伤害
if(P_hp<=) //死一个射手
{
P_hp=;
totpnum--; pnum--;
nowstep=;
}
if(Z_hp<=){ Z_hp=; znum--; } //死一个僵尸
}
if(pnum<=&&znum>) return true; //所有豌豆射手挂掉而僵尸有多的
return false;
}
int BIS(int totpnum,int pnum) //二分
{
int x=,y=*maxn,mid;
while(x<=y)
{
mid=(x+y)/;
if(judge(totpnum,pnum,mid)) y=mid-;
else x=mid+;
}
return y+;
}
int solve()
{
int ret=; //ret是需要的僵尸的个数
if(S[L]=='M') { ret++; L--; step=; } //最右边是土豆,step代表走到下一个位置需要的步数
else step=;
while(L>=) //知道小于0才算赢
{
if(S[L]=='M') //是土豆
{
if(step>) //往前走
{
step--;
if(Pnum>=) ret++; //超过50个豌豆射手死一个僵尸
continue;
}
else ret++; //炸死一个
Mnum--; L--;
step=; //step变为2
}
else //如果是豌豆射手
{
int pnum=;
for(int i=L;i>=;i--) //一直到找到土豆
if(S[i]=='M') break;
else pnum++;
ret+=BIS(Pnum,pnum); //二分得到最小的僵尸个数
Pnum-=pnum;
L-=pnum+; //多减1表示把土豆算进去了,因为有没死的僵尸在土豆处牺牲
step=;
}
}
if(S[]=='M') ret++; //如果最左边是土豆,则还需要一个僵尸去攻击首脑
return ret;
}
int main()
{
int T,Case=;
scanf("%d",&T);
while(T--)
{
scanf("%s",S); //植物
init();
printf("Case %d: %d\n",++Case,solve());
}
return ;
}
Hdu3640-I, zombie(模拟+二分)的更多相关文章
- FZU 1575 小学生的游戏【模拟二分】
某天,无聊的小斌叫上几个同学玩游戏,其中有比较笨的小兴,比较傻的小雪,可爱的小霞和自以为是的小楠.他们去找聪明的小明去给他们当裁判.判定谁取得游戏胜利. 而这个游戏是由小斌想个1到10000000的数 ...
- Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) A B C D 水 模拟 二分 贪心
A. Is it rated? time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- UVALive 3971 Assemble(模拟 + 二分)
UVALive 3971 题意:有b块钱.想要组装一台电脑,给出n个配件的种类,名字,价格,品质因子.若各种类配件各买一个,总价格<=b,求最差品质配件的最大品质因子. 思路: 求最大的最小值一 ...
- bzoj4717 改装 模拟+二分
Description [题目背景] 小Q最近喜欢上了一款游戏,名为<舰队connection>,在游戏中,小Q指挥强大的舰队南征北战,从而成为了一名dalao.在游戏中,不仅船只能力很重 ...
- Largest Allowed Area【模拟+二分】
Largest Allowed Area 题目链接(点击) 题目描述 A company is looking for land to build its headquarters. It has a ...
- Codeforces Round #481 (Div. 3) C. Letters (模拟,二分)
题意:有个\(n\)个公寓,每个公寓\(a_{i}\)代表着编号为\(1-a_{i}\)个房间,给你房间号,问它在第几栋公寓的第几个房间. 题解:对每个公寓的房间号记一个前缀和,二分查找属于第几个公寓 ...
- 模拟+二分 poj-1019-Number Sequence
题目链接: http://poj.org/problem?id=1019 题目大意: Sk表示123...k 把S1S2S3...Sk排成一行 比如:112123123412345123456.... ...
- Codeforces 404E: Maze 1D(二分)
题意:指令“R”机器人会向右走一步,“L”是向左.起初机器人在0位置,可以在除了0以外的任何位置放障碍,如果机器人的指令将使它走到障碍上,那这一步他会保持不动.要求让机器人最终结束的那一步一定只走过一 ...
- NOIP模拟测试7
期望得分:60+60+60 实际得分:60+60+0 这次考试主要是T3搜索打挂了(我可是靠搜索吃饭的); 1.数组开小了,不过开大数组只拿到了10分的好成绩. 2.题意没审清(其实是他没说清). 以 ...
随机推荐
- error recoder,error debug for openStack kilo
- java 读取mysql库表数据
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import ...
- [hihocoder 1033]交错和 数位dp/记忆化搜索
#1033 : 交错和 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 给定一个数 x,设它十进制展从高位到低位上的数位依次是 a0, a1, ..., an - 1 ...
- top 命令SQLServer-sybase-oracle
SQLServer: select top 10 * from tablename; select top 10 percent from tablename; select * from table ...
- HTTP 503 错误 – 服务不可用 (Service unavailable)
介绍 因暂时超载或临时维护,您的 Web 服务器目前无法处理 HTTP 请求. 其含义是, 这是一个暂时情况,会有一些延误, 过 后将会得到缓解. 有些服务器在这种情况下也许干脆拒绝套接字(socke ...
- 安装软件配置VC++环境时常出现的问题--Error 1935.安装程序集
装很多软件是都要配置VC++环境的,但由于系统注册表限制,很多时候软件安装过程中会报如下错误 安装 vc++2005 运行库 Error 1935.安装程序集 Microsoft.vc80.atl,t ...
- 微软HoloLens虚拟现实可以开发了。
1.microsoft-hololens-now-available-to-developers 2.http://www.microsoft.com/microsoft-hololens/en-us ...
- js-浏览器DOM
1.window尺寸 适配所有浏览器的尺寸方案 var w=window.innerWidth|| document.documentElement.clientWidth|| document.bo ...
- (转)用Eclipse编译你的ROS程序
原地址: http://blog.csdn.net/sujun3304/article/details/18572017 好了,理解了系统各个组件的含义后,还是直接进入程序真刀真枪的从实践中学习吧! ...
- 关于页面刷新或者调用方法事获取不到元素信息或者出现缺少对象错误的换位思考setTimeout的使用
这两天客户的需求不能定下来,做闲人好长时间了,不如来整理下最近碰到的一些个小麻烦. 正题: 场景一. 最近在开发的过程中使用到了百度的富客户端文本编辑器(ueditor)---这是一款功能很强大的文本 ...