zoukankan      html  css  js  c++  java
  • hdu 5596 GTW likes gt

    Problem Description
    Long long ago, there were n adorkable GT. Divided into two groups, they were playing games together, forming a column. The i−th GT would randomly get a value of ability bi. At the i−th second, the i−th GT would annihilate GTs who are in front of him, whose group differs from his, and whose value of ability is less than his.
    
    In order to make the game more interesting, GTW, the leader of those GTs, would emit energy for m times, of which the i−th time of emitting energy is ci. After the ci second, b1,b2,...,bci would all be added 1.
    
    GTW wanted to know how many GTs would survive after the n−th second.
    Input
    The first line of the input file contains an integer T(≤5), which indicates the number of test cases.
    
    For each test case, there are n+m+1 lines in the input file.
    
    The first line of each test case contains 2 integers n and m, which indicate the number of GTs and the number of emitting energy, respectively.(1≤n,m≤50000)
    
    In the following n lines, the i−th line contains two integers ai and bi, which indicate the group of the i−th GT and his value of ability, respectively. (0≤ai≤1,1≤bi≤106)
    
    In the following m lines, the i−th line contains an integer ci, which indicates the time of emitting energy for i−th time.
    Output
    There should be exactly T lines in the output file.
    
    The i−th line should contain exactly an integer, which indicates the number of GTs who survive.
     
    Sample Input
    1
    4 3
    0 3
    1 2
    0 3
    1 1
    1
    3
    4
     
    Sample Output
    3

    Hint
     
    Source
     
    问这个数与之后比它大的数的影响的。可以从后往前面扫,记最大值,如果碰到比最大值小的,去掉即可。
     
     1 #include<stdio.h>  
     2 #include<algorithm>  
     3 #include<math.h>  
     4 #include<queue>  
     5 #include<string.h>  
     6 #include<stack>  
     7 using namespace std;  
     8 const int  maxn = 1e5+10;  
     9 int c[maxn];  
    10 struct node  
    11 {  
    12     int data;  
    13     int id;  
    14 }a[maxn];  
    15 int main()  
    16 {  
    17     int T;  
    18     scanf("%d",&T);  
    19     while(T--)  
    20     {  
    21       int  n,m;  
    22       scanf("%d%d",&n,&m);  
    23       for(int i = 1;i<=n;i++)  
    24       {  
    25           scanf("%d%d",&a[i].id,&a[i].data);  
    26       }  
    27       int x;  
    28       memset(c,0,sizeof(c));  
    29         for(int i = 1;i<=m;i++)  
    30           {  
    31               scanf("%d",&x);  
    32               c[x]++;  
    33           }  
    34           int ans= n;  
    35           int max1= -1;  
    36           int max2= -1;  
    37           for(int i= n;i>=1;i--)  
    38           {    max1-=c[i];  
    39                max2-=c[i];  
    40               if(a[i].id ==1)  
    41                {  //max1-=c[i];  
    42                    if(a[i].data<max2)  
    43                    {  
    44                        ans--;  
    45                    }  
    46                    max1= max(max1,a[i].data);  
    47               }  
    48               else  
    49               {  
    50                  if(a[i].data<max1)  
    51                    {  
    52                        ans--;  
    53                    }  
    54                    max2= max(max2,a[i].data);  
    55               }  
    56           }  
    57           printf("%d
    ",ans);  
    58     }  
    59     return 0;  
    60 }  
    View Code
     
  • 相关阅读:
    NullPointerException
    面试oracle 经常问的一个问题- 事务
    python 之 import、from、as 关键字的 白话 解释与例子
    python 学习 之 第二章(条件、循环和其他语句)
    python学习 之 第一章 (简单例子与常用数据类型)
    python中常用函数含义记录
    python 2 版本中的input() 和 raw_input() 函数的比较
    字符串处理关键字str 和 repr
    文件操作-一个可以直接复制文件数据的小程序
    C语言 32个关键字
  • 原文地址:https://www.cnblogs.com/UniqueColor/p/5223667.html
Copyright © 2011-2022 走看看