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 ...
随机推荐
- Python基础篇(八)
key words:私有变量,类静态变量,生成器,导入Python模块,r查看模块可以使用的函数,查看帮助信息,启动外部程序,集合,堆,时间模块,random模块,shelve模块,文件读取等 > ...
- 三栏布局,div左右盒子是定宽,中间是自适应
用弹性布局flex: 给父盒子加个display:flex; 给中间盒子设flex=1; /* 弹性盒子布局*/ .wrap{ width: 100%; height: 90px; display: ...
- c语言环境初始化&c语言和汇编混合编程
bootloader通常会分为两个阶段:第一阶段采用汇编语言来编写,主要是一些核心的初始化工作(内存,时钟的初始化),第二阶段使用C语言来编写,主要是它会完成一些板载硬件的初始化(串口,网口)然后其启 ...
- Redis 学习(三) —— 事务、消息发布订阅
一.Redis事务 Redis 提供的事务机制与传统的数据库事务有些不同,传统数据库事务必须维护以下特性:原子性(Atomicity), 一致性(Consistency),隔离性(Isolation) ...
- web前端 ajax请求上传图片数据类型处理
form: function (url, paras, files, success) {//上传的文件类型是MultipartFile[]//如果把需要的参数直接传入,则会请求错误//设置请求参数的 ...
- 浅讲JUnit
JUnit单元简介: JUnit ----是一个开发源码的java测试框架,用于编写和运行可重复的测试,它是用于单元测试框架体系xUnit的一个实例, 用于java语言,主要用于白盒测试,回 ...
- img alt与title的区别
前端 alt是图片加载不出来时候,对图片的文本替代 title 是鼠标放在图片上时,对图片的进一步说明 seo 搜索引擎对图片意思的理解主要靠 alt
- MySql主键自动生成,表、实体、C#调用方法
1.表:mysql建表语句 DROP TABLE IF EXISTS `keycode`; CREATE TABLE `keycode` ( `Id` ) NOT NULL AUTO_INCREMEN ...
- Linux 上 C 程序的内存布局
在仔细研究这个问题之前,我认为 C 程序在内存中只有代码段,堆和栈三部分构成.前几天面试被问到了这个问题,才发现自己的印象是不完全的. 在本文中通过解析析一个 C 程序中变量和函数的地址来分析 C 程 ...
- 获取登陆用户的ip
function getip(){ static $ip = null; if($ip !=null) return $ip; if(getenv('REMOTE_ADDR') ...