zoukankan      html  css  js  c++  java
  • TOJ 4120 Zombies VS Plants

     

    链接:http://acm.tju.edu.cn/toj/showp4120.html
    4120.   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()!='
    ');
    		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=='
    '){
    					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
    ",sum);
    	}
    	return 0;
    }
  • 相关阅读:
    (1)ASCⅡ码与一般乘除与逻辑指令
    (2)串指令的传送
    【转】伟大的代码(97年的Mekka ’97 4K Intro比赛的一等奖作品)汇编机器码
    第四次游戏革命:全息游戏 from:http://www.cnblogs.com/alamiye010/archive/2012/08/15/2640881.html
    sqlce wp
    wp7 blogs
    单例的两种实现方式
    C# event from:http://www.cnblogs.com/leslies2/archive/2012/03/22/2389318.html#a4
    wp7——sqlite数据库操作 from:http://blog.csdn.net/wp_lijin/article/details/7370790
    Linq C#增删改查
  • 原文地址:https://www.cnblogs.com/Basasuya/p/8433779.html
Copyright © 2011-2022 走看看