TOJ 4120 Zombies VS Plants
链接:http://acm.tju.edu.cn/toj/showp4120.html4120. Zombies VS Plants
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 268 Accepted Runs: 36
tmeteorj recently is interested in a game Plants VS Zombies like following picture.
And his brain hole is opened so he want to you to solve this problem.
Your role is zombies' manager, and your task is place enough zombies to eat all plants on each line.
The rules are as follows:
1.Each zombies has health point from 1 to infinity.
2.Each plants has its attack point which we will tell you and will not greater than 1000.
3.All plants are so afraid of zombies, so if a plant's attack point is not greater than it's line's zombie's HP, this plant will be scared silly. So its attack point will become zero.
4.Zombies eat plants from right to the left.
5.You can place any number of zombies on each line.
Your task is to calculate the minimal total zombies' HP you need to place in order to eat all plants.
INPUT
First line, there will a number T(T≤10), means the test case of this problem.
After this, there will be a number n(n≤100), means there are n lines in the yard.
Each line contains several plants' attack points. The plants' number will not greater than 100.
There may be some blanks in anywhere.
OUTPUT
For each case, print the minimal HP for the question.
Sample Input
3
2
1 2 3 4 5
2 3 4 5
1
1 2 3 4 5
2
1 2 3 4 5 6
1 2
Sample Output
10
5
8
/*
遇见过的最坑的题目,主要坑点在与输入会在各处出现空格
听说还可能出现一行1500空格....
所以得用好getchar,这是关键
*/
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
int i,j,k,zhi,fu,flag,N,T;
char ch;
int sum,mx ;
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
while(getchar()!='\n');
sum=0;
for(int i=1;i<=N;i++){
flag=0;
zhi=0;
fu=1;
mx=1;
while(1){
ch=getchar();
if(ch=='-'){
flag=1;
fu=-1;
}
else if(ch==' '){
mx=max(mx,fu*zhi);
fu=1;
zhi=0;
}
else if(ch=='\n'){
if(flag){
mx=max(mx,fu*zhi);
fu=1;
zhi=0;
}
else mx=0;
break;
}
else{
zhi=zhi*10+ch-'0';
flag=1;
}
}
sum+=mx;
}
printf("%d\n",sum);
}
return 0;
}
TOJ 4120 Zombies VS Plants的更多相关文章
- Bzoj 1565: [NOI2009]植物大战僵尸 最大权闭合图,拓扑排序
题目: http://cojs.tk/cogs/problem/problem.php?pid=410 410. [NOI2009] 植物大战僵尸 ★★★ 输入文件:pvz.in 输出文件:p ...
- tyvj P1135 - 植物大战僵尸 最大权闭合图
P1135 - 植物大战僵尸 From ytt Normal (OI)总时限:10s 内存限制:128MB 代码长度限制:64KB 背景 Background 虽然这么多天了,,虽然 ...
- 图论(网络流):COGS 410. [NOI2009] 植物大战僵尸
410. [NOI2009] 植物大战僵尸 ★★★ 输入文件:pvz.in 输出文件:pvz.out 简单对比时间限制:2 s 内存限制:512 MB [问题描述] Plants vs ...
- BZOJ1565[NOI2009]植物大战僵尸——最大权闭合子图+拓扑排序
题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻.该款游戏包含多 ...
- 【刷题】BZOJ 1565 [NOI2009]植物大战僵尸
Description Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻. ...
- 洛谷 P2805 [NOI2009]植物大战僵尸 解题报告
P2805 [NOI2009] 植物大战僵尸 题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plan ...
- BZOJ1565:[NOI2009]植物大战僵尸——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1565 https://www.luogu.org/problemnew/show/P2805 Pla ...
- bzoj1565【NOI2009】植物大战僵尸(最小割)
题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻.该款游戏包含多 ...
- COGS410. [NOI2009] 植物大战僵尸
410. [NOI2009] 植物大战僵尸 ★★★ 输入文件:pvz.in 输出文件:pvz.out 简单对比时间限制:2 s 内存限制:512 MB [问题描述] Plants vs ...
随机推荐
- 浅谈JavaScript的事件(事件类型)
Web浏览器能够发生的事件有很多种类型,不同的事件类型有不同的事件信息.DOM3级的事件类型主要包括:UI事件,用户与页面上的元素交互时触发:焦点事件,元素获得或失去焦点触发:鼠标事件,用户通过鼠标在 ...
- java 实现websocket的两种方式
简单说明 1.两种方式,一种使用tomcat的websocket实现,一种使用spring的websocket 2.tomcat的方式需要tomcat 7.x,JEE7的支持. 3.spring与we ...
- Windows Server 2016-抢占FSMO角色
很多情况下,当生产域控制器发生问题无法修复的情况下,我们只能通过抢占FSMO角色以保证用户验证等正常或及时恢复.一般在同一个域环境中,我们往往都会有主备或主辅域控规划,平时工作的时候,两台域控可以实现 ...
- javascript Map和Set
Map和Set JavaScript的默认对象表示方式{}可以视为其他语言中的Map或Dictionary的数据结构,即一组键值对. 但是JavaScript的对象有个小问题,就是键必须是字符串.但实 ...
- 共享表空间VS独立表空间
基础概念:共享表空间 VS 独立表空间 [共享表空间] 又称为system tablespace系统表空间,a small set of data files (the ibdata files) . ...
- 换行符\r \n LF
前言:在对照PSR-2规范时,看到文件结尾必须要以Unix LF(linefeed)结尾,不懂查~ 来源于:http://www.cppblog.com/prayer/archive/2009/08/ ...
- js利用闭包封装自定义模块的几种方法
1.自定义模块: 具有特定功能的js文件 将所有的数据和功能都封装在一个函数的内部 只向外暴露一个包含有n个方法的对象或者函数 模块使用者只需要通过模块暴露的对象调用方法来实现相对应的功能 1.利用函 ...
- SpringBoot中过滤器、监听器以及拦截器
属于javax.servlet所提供的Api 拦截器原理 简单来讲是通过动态代理实现,被访问的目标方法通过代理类(方法)来执行,这样我们就可以在真正要执行的方法执行前.后做一些处理: 通过拦截器这种方 ...
- 如何解决使用Gradle时出现的jar包冲突
前言 在我之前使用Gradle的博文中已经提到,Gradle对依赖的管理是比较智能的,如果有两个包依赖于相同的包,而版本不同的时候,Gradle会进行自动的选择,从而避免jar包的冲突. 也就是说,在 ...
- python模拟登录浙江大学彩云库
前言: 群里一位朋友叫我帮他写 一个模拟登录的. 代码: import requests import time url="http://yk3.gokuai.com/web/index&q ...