链接: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. 洛谷 [P2764]最小路径覆盖问题

    二分图应用模版 #include <iostream> #include <cstdio> #include <algorithm> #include <cs ...

  2. Oracle的order by的中文排序问题

    Oracle 中查询结果按照某个中文字段或者英文字母(包括 符号)排序,并不会得到我们预期的结果,因为对于中文与英文字母及符号,Oracle实际是按照其对应的ASCII码值排序的! 可以看到按照中文村 ...

  3. Matplotlib学习笔记(一)

    原   matplotlib学习笔记 参考:Python数据科学入门教程 Python3.6.1 jupyter notebook .caret, .dropup > .btn > .ca ...

  4. 运行所选代码生成器时出错:“预期具有协定名称 "NuGet.VisualStudio.IVsPackageInstallerServices" 的1导出 ——VS2015错误记录

    在编写ASP.NET MVC控制器后,右键添加视图时,VS2015报出错误: 运行所选代码生成器时出错:“预期具有协定名称 "NuGet.VisualStudio.IVsPackageIns ...

  5. jquery $(document).ready() 与window.onload的区别(转)

    Jquery中$(document).ready()的作用类似于传统JavaScript中的window.onload方法,不过与window.onload方法还是有区别的. 1.执行时间 windo ...

  6. 【动画】JQuery实现冒泡排序算法动画演示

    1 前言 冒泡排序是大家最熟悉的算法,也是最简单的排序算法,因其排序过程很象气泡逐渐向上漂浮而得名.为了更好的理解其基本的思想,毛三胖利用JQuery实现了冒泡排序的动画演示,并计划陆续实现其它排序算 ...

  7. html2canvas在微信中无法使用

    html2canvas: https://github.com/niklasvh/html2canvas 本来想在微信网页中使用html2canvas生成图片,结果死活不行 测试发现在Chrome,手 ...

  8. PHP实现水印效果(文字、图片)

    第一种 <?php /** * 功能:给一张图片加上水印效果 * $i 要加水印效果的图片 * $t 水印文字 * $size 文字大小 * $pos 水印的位置 * $color 文字的颜色 ...

  9. uva12325 暴力枚举

    这题刚开始我就贪心,直接wrong了,贪心适合可以取一个物体部分的题. 还是老实枚举吧,注意枚举要分类,不然可能会超时,还有注意答案是long long AC代码: #include<cstdi ...

  10. Zookeeper笔记3——原理及其安装使用

    Zookeeper到底能干什么? 1.配置管理:这个好理解.分布式系统都有好多机器,Zookeeper提供了这样的一种服务:一种集中管理配置的方法,我们在这个集中的地方修改了配置,所有对这个配置感兴趣 ...