zoukankan      html  css  js  c++  java
  • BestCoder Round #66 1002

    GTW likes gt

     
     Accepts: 75
     
     Submissions: 261
     Time Limit: 2000/1000 MS (Java/Others)
     
     Memory Limit: 131072/131072 K (Java/Others)
    Problem Description

    Long long ago, there were nn adorkable GT. Divided into two groups, they were playing games together, forming a column. The ith GT would randomly get a value of ability bi​​. At the ith second, the ith 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 mm times, of which the ith 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 nth second.

    Input

    The first line of the input file contains an integerT(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 nn and mm, which indicate the number of GTs and the number of emitting energy, respectively.(1n,m50000)

    In the following nn lines, the ith line contains two integers ai​​ and bi​​, which indicate the group of the ith GT and his value of ability, respectively. (0ai​​1,1bi​​10^6​​)

    In the following mm lines, the ith line contains an integer ci​​, which indicates the time of emitting energy for ith time.

    Output

    There should be exactly T lines in the output file.

    The ith 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
    After the first seconds,b1​​=4,b2​​=2,b3​​=3,b4​​=1 After the second seconds,b1​​=4,b2​​=2,b3​​=3,b4​​=1 After the third seconds,b1​​=5,b2​​=3,b3​​=4,b4​​=1,and the second GT is annihilated by the third one. After the fourth seconds,b1​​=6,b2​​=4,b3​​=5,b4​​=2 ci​​ is unordered.

    GTW likes gt

     
     Accepts: 75
     
     Submissions: 261
     Time Limit: 2000/1000 MS (Java/Others)
     
     Memory Limit: 131072/131072 K (Java/Others)
    问题描述
    从前,有nn只萌萌的GT,他们分成了两组在一起玩游戏。他们会排列成一排,第i只GT会随机得到一个能力值bi​​。在第i秒的时候,第i只GT可以消灭掉所有排在他前面的和他不是同一组的且能力值小于他的GT。
    为了使游戏更加有趣,GT的首领GTW会发功mm次,第ii次发功的时间为ci​​,则在第ci​​秒结束后,b1​​,b2​​,...,bci​​​​都会增加1。
    现在,GTW想知道在第nn秒之后,会有几只GT存活下来。
    输入描述
    第一行只有一个整数T(T5),表示测试数据组数。
    第二行有两个整数n,m。表示GT的个数和GTW发功的次数。( 500001n50000,1m50000)
    第三到n+2行,每行有两个整数ai​​,bi​​,表示第ii只GT在哪个组和他的能力值 (0a[i]1,1b[i]106​​)
    第n+3行到第n+m+2行,每行有一个整数ci​​,表示GTW第i次发功的时间。 1c[i]n
    
    输出描述
    总共T行,第i行表示第i组数据中,GT存活的个数。
    
    输入样例
    1
    4 3
    0 3
    1 2
    0 3
    1 1
    1
    3
    4
    输出样例
    3
    Hint
    1秒后 能力值为4 2 3 1
    第2秒后 能力值为4 2 3 1
    第3秒后 能力值为5 3 4 1,第2只GT被第3只GT消灭掉了
    第4秒后 能力值为6 4 5 2
    ci​​并不是有序的
    我们先通过题意先计算出最后他们有多少能力值,然后,我们用两个容器分别装他们,如果可以干掉,就把它删除,然后就两个容器大小之和就好
    #include<stdio.h>
    //#include<bits/stdc++.h>
    #include<string.h>
    #include<iostream>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<queue>
    #include<map>
    #include<vector>
    #include<algorithm>
    #include<limits.h>
    #define inf 0x3fffffff
    #define INF 0x3f3f3f3f
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define ULL unsigned long long
    using namespace std;
    map<int,int> q;
    multiset<int> q0;
    multiset<int> q1;
    multiset<int>::iterator it;
    int i,j;
    int t;
    int n,m;
    struct P
    {
        int a,b;
    }L[100000];
    int c;
    int main()
    {
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&n,&m);
            for(i=1;i<=n;i++)
            {
                scanf("%d%d",&L[i].a,&L[i].b);
            }
            for(i=1;i<=m;i++)
            {
                scanf("%d",&c);
                q[c]++;
            }
            for(i=n-1;i>=1;i--)
            {
                q[i]+=q[i+1];
            }
            for(i=1;i<=n;i++)
            {
                L[i].b+=q[i];
              //  cout<<L[i].b<<endl;
            }
            for(i=1;i<=n;i++)
            {
                if(L[i].a==0)
                {
                    while(q1.size())
                    {
                        it=q1.begin();
                        if(*it<L[i].b)
                        {
                            q1.erase(it);
                        }
                        else
                        {
                            break;
                        }
                    }
                    q0.insert(L[i].b);
                }
                else if(L[i].a==1)
                {
                    while(q0.size())
                    {
                        it=q0.begin();
                        if(*it<L[i].b)
                        {
                            q0.erase(it);
                        }
                        else
                        {
                            break;
                        }
                    }
                    q1.insert(L[i].b);
                }
            }
          //  cout<<q0.size()+q1.size()<<endl;
          printf("%d
    ",q0.size()+q1.size());
            q.clear();q0.clear();q1.clear();
        }
    
        return 0;
    }
    

      

     
  • 相关阅读:
    JVM-对象的创建
    maven依赖无法下载依赖包,PKIX认证不通过
    Object里面的方法
    Java多线程之volatile与synchronized比较
    java 二叉树的创建 遍历
    设计模式之单例模式
    博客园自定义主题 皮肤
    mysql索引 b+树
    sleep和wait的区别(转)
    final/finally/finalize的区别(转)
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5059593.html
Copyright © 2011-2022 走看看