• 炉石传说__multiset


     炉石传说

     Problem Description

    GG学长虽然并不打炉石传说,但是由于题面需要他便学会了打炉石传说。但是传统的炉石传说对于刚入门的GG学长来说有点复杂,所以他决定自己开发一个简化版的炉石传说。

    在简化版的炉石传说中:

    每个随从只有生命值和攻击力,并且在你的回合下,你的每只随从在本回合下只能选择一个敌方随从进行攻击。当两个随从a,b交战时,a的生命值将减去b的攻击力,b的生命值将减去a的攻击力,(两个伤害没有先后顺序,同时结算)。如果a或b的生命值不大于0,该随从将死亡。

    某一次对局中,GG学长和对手场面上均有n个随从,并且是GG学长的回合。由于GG学长是个固执的boy,他一定要在本回合杀死对方所有随从,并且保证自己的随从全部存活。他想知道能否做到。

     Input

    第一行为T,表示有T组数据。T<=100。

    每组数据第一行为n,表示随从数量(1 <= n <= 100)

    接下来一行2 * n个数字a1, b1, a2, b2, ... , an, bn (1 <= ai, bi <= 100)

    表示GG学长的n个随从,ai表示随从生命,bi表示随从攻击力

    接下来一行2 * n个数字c1, d1, c2, d2, ... , cn, dn (1 <= ci, di <= 100)

    表示对手的n个随从,ci表示随从生命,di表示随从攻击力。

     Output

    每组数据,根据GG是否能完成他的目标,输出一行”Yes”或”No”。

     Sample Input

    2 3 4 4 5 5 6 6 1 1 2 2 3 3 3 4 4 5 5 6 6 1 4 2 4 3 4

     Sample Output

    Yes No

    题解:两种思路从小到大排序,由a找b,从大到小排序,由b找a,第二种思路简单,第一种思路超时。。。;

    题意可以转化成矩形嵌套的最大个数,把a的血量减1;

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    #include<set>
    using namespace std;
    const int INF = 0x3f3f3f3f;
    const int MAXN = 100010;
    struct Node{
        int x, y;
        friend bool operator < (Node a, Node b){
            if(a.x != b.x)
                return a.x > b.x;
            else
                return a.y > b.y;
        }
        void init(){
            scanf("%d%d", &this->x, &this->y);
        }
        void init2(){
            scanf("%d%d", &this->y, &this->x);
        }
    };
    Node GG[MAXN], aga[MAXN];
    multiset<int>st;
    int main(){
        int T, N;
        scanf("%d", &T);
        while(T--){
            scanf("%d", &N);
            for(int i = 0; i < N; i++){
                GG[i].init();
                GG[i].x--;
            }
            for(int j = 0; j < N; j++){
                aga[j].init2();
            }
            sort(GG, GG + N);
            sort(aga, aga + N);
            st.clear();
            multiset<int>::iterator iter;
            int ans = 0;
            for(int i = 0, j = 0; i < N; i++){
                while(j < N && aga[i].x <= GG[j].x){
                    st.insert(GG[j].y);
                    j++;
                }
                if(st.empty())continue;
                iter = st.lower_bound(aga[i].y);
                if(iter == st.end())continue;
                ans++; st.erase(iter);
            }
            if(ans == N)
                puts("Yes");
            else
                puts("No");
        }
        return 0;
    }
  • 相关阅读:
    Linux 安装jdk 报错 Error: could not find libjava.so Error: Could not find Java SE Runtime Environment.
    k8s 挂载ceph rbd
    spinnaker结合表达式实现发版时下拉列表选择docker image
    istio环境集成zipkin
    istio 日志打印 request body 和respon body
    jenkins任务中无法执行sudo,管理员操作
    ansible根据shell命令返回值,判断是否应该急继续往下执行
    ReplicaSetController、ReplicationController
    kubeproxy
    PodGCController
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5455920.html
Copyright © 2020-2023  润新知