链接: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的更多相关文章

  1. Bzoj 1565: [NOI2009]植物大战僵尸 最大权闭合图,拓扑排序

    题目: http://cojs.tk/cogs/problem/problem.php?pid=410 410. [NOI2009] 植物大战僵尸 ★★★   输入文件:pvz.in   输出文件:p ...

  2. tyvj P1135 - 植物大战僵尸 最大权闭合图

    P1135 - 植物大战僵尸 From ytt    Normal (OI)总时限:10s    内存限制:128MB    代码长度限制:64KB 背景 Background 虽然这么多天了,,虽然 ...

  3. 图论(网络流):COGS 410. [NOI2009] 植物大战僵尸

    410. [NOI2009] 植物大战僵尸 ★★★   输入文件:pvz.in   输出文件:pvz.out   简单对比时间限制:2 s   内存限制:512 MB [问题描述] Plants vs ...

  4. BZOJ1565[NOI2009]植物大战僵尸——最大权闭合子图+拓扑排序

    题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻.该款游戏包含多 ...

  5. 【刷题】BZOJ 1565 [NOI2009]植物大战僵尸

    Description Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻. ...

  6. 洛谷 P2805 [NOI2009]植物大战僵尸 解题报告

    P2805 [NOI2009] 植物大战僵尸 题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plan ...

  7. BZOJ1565:[NOI2009]植物大战僵尸——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1565 https://www.luogu.org/problemnew/show/P2805 Pla ...

  8. bzoj1565【NOI2009】植物大战僵尸(最小割)

    题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻.该款游戏包含多 ...

  9. COGS410. [NOI2009] 植物大战僵尸

    410. [NOI2009] 植物大战僵尸 ★★★   输入文件:pvz.in   输出文件:pvz.out   简单对比时间限制:2 s   内存限制:512 MB [问题描述] Plants vs ...

随机推荐

  1. 百度地图api 区级以下行政区划

    我们在使用百度地图api想要展示苏州市吴中区各乡镇的行政区范围: 百度api有提供了“添加行政区划”的示例:http://lbsyun.baidu.com/jsdemo.htm#c1_10 但该功能目 ...

  2. VS2012如何调试JS

    下面的操作步骤描述了怎样利用vs.net中的调试器来调试javascript: 1,首先,要让你的ie允许调试脚本,具体步骤如下:    打开ie->工具菜单->inter选项->高 ...

  3. ACE_TEST1.obj : error LNK2019: 无法解析的外部符号

    ACE_TEST1.obj : error LNK2019: 无法解析的外部符号 "int __cdecl ace_main_i(int,char * * const)" (?ac ...

  4. LeetCode - 653. Two Sum IV - Input is a BST

    Given a Binary Search Tree and a target number, return true if there exist two elements in the BST s ...

  5. jQuery中animate()方法用法实例

    本文实例讲述了jQuery中animate()方法用法.分享给大家供大家参考.具体分析如下: 此方法用于创建自定义动画,并且能够规定动画执行时长.擦除效果.动画完成后还可以地触发一个回调函数. ani ...

  6. ★Linux命令行操作技巧(作为服务器端)

    1.统计某个目录下总共有多少个文件(递归统计所有子目录)ls -lR|grep "^-"|wc -l

  7. Linux系统内存占用90%以上——解决方法

    Linux系统内存占用90%以上--解决方法   首先要明确一个问题:Linux系统内存占用90%以上,是否属于正常范围?网上有详细的解释,这属于正常现象~~~    www.2cto.com   L ...

  8. ansible实践4- 管理配置文件

    生产环境中大多时候是需要管理配置文件的,安装软件包只是在初始化环境的时候用一下.下面我们来写个管理nginx配置文件的playbook   mkdir  -p /etc/ansible/nginx_c ...

  9. 接口测试基础(fiddler、postman的使用、python实现测试接口程序)

    写在前面:本文主要的章节规划: 1.什么是接口测试    另外,有的时候会直接调用别的公司的接口,比如银行的.淘宝的.支付宝的,此时也需要做接口测试以及验证数据: 做接口测试的好处:      其中, ...

  10. [原创]Oracle 12c的备份和恢复策略

    Oracle 12c的备份和恢复策略(RMAN备份[开启归档/控制文件/数据文件/归档日志]): 备份策略: * 每半年做一个数据库的全备份(包括所有的数据和只读表空间) * 每周做一次零级备份 * ...