• HDU 5596 ——GTW likes gt——————【想法题】


    GTW likes gt

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
    Total Submission(s): 833    Accepted Submission(s): 299


    Problem Description
    Long long ago, there were n 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 m 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 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.(1n,m50000)

    In the following n lines, the ith line contains two integers ai and bi, which indicate the group of the ith GT and his value of ability, respectively. (0ai1,1bi106)

    In the following m 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,$b_1=4,b_2=2,b_3=3,b_4=1$ After the second seconds,$b_1=4,b_2=2,b_3=3,b_4=1$ After the third seconds,$b_1=5,b_2=3,b_3=4,b_4=1$,and the second GT is annihilated by the third one. After the fourth seconds,$b_1=6,b_2=4,b_3=5,b_4=2$ $c_i$ is unordered.
     
    Source
     

    题目大意:有n个gt(认为是一种动物),每个有一个法力值b[i],有0,1两个组,在第i秒的时候,第i只gt可以消灭前面不跟他一组且法力值小于他的gt。有一个巫师,发m次功,在c[i]秒的时候发功,在第c[i]秒结束后,b[i],b[2]...b[c[i]]都会增加1。问你最后活下来的有多少只gt。

    解题思路:倒着处理,首先预处理出来第i秒时第i只gt的法力值增量dv[i]。然后维护每组当前的最大法力值Max。对于每只gt,我们判断他跟另外一组最大法力值的关系,同时维护该组的最大法力值。

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e6+2000;
    struct GT{
        int group,val;
    }gts[maxn];
    int dv[maxn], b[maxn];
    int main(){
        int T,n,m;
        scanf("%d",&T);
        while(T--){
            scanf("%d%d",&n,&m);
            for(int i = 1;i <= n; i++){
                scanf("%d%d",&gts[i].group,&gts[i].val);
                dv[i] = 0;
            }
            dv[n+1] = 0;
            for(int i = 1;i <= m; i++){
                scanf("%d",&b[i]);
                dv[b[i]]++;
            }
            for(int i = n; i >= 1; i--){
                dv[i] += dv[i+1];
            }
            int Max0 = -1, Max1 = -1, ans = 0;
            for(int i = n; i >= 1; i--){
                if(gts[i].group == 1){
                    if(gts[i].val + dv[i] < Max0){
                        ans++;
                    }
                    if(gts[i].val + dv[i] > Max1){
                        Max1 = gts[i].val + dv[i];
                    }
                }else{
                    if(gts[i].val + dv[i] < Max1){
                        ans++;
                    }
                    if(gts[i].val + dv[i] > Max0){
                        Max0 = gts[i].val + dv[i];
                    }
                }
            }
            printf("%d
    ",n-ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    bat 实现主机hostname的修改
    我的影视作品,如何在博客园发布带有CSS样式的HTML
    java实现Windows记事本
    cmd 执行Dcpromo错误:在该 SKU 上不支持 Active Directory 域服务安装向导,Windows Server 2008 R2 Enterprise 配置AD(Active Directory)域控制器
    警告: 正保存的数据被裁断到 1024 字符。 错误: 拒绝访问注册表路径。
    山西大同大学教务处教师端——可在PC端,手机端操作
    bat脚本+diskpart 脚本实现自动划分磁盘分区
    山西大同大学教务处学生端--送给学弟,学妹的礼物,可在PC端,手机端操作
    ECharts
    javascript删除数组里的对象
  • 原文地址:https://www.cnblogs.com/chengsheng/p/5057763.html
Copyright © 2020-2023  润新知