zoukankan      html  css  js  c++  java
  • UVA LA 7146 2014上海亚洲赛(贪心)

    https://icpcarchive.ecs.baylor.edu/index.php?

    option=com_onlinejudge&Itemid=8&page=show_problem&category=648&problem=5158&mosmsg=Submission+received+with+ID+1708713

    /**
    UVA LA  7146  2014上海亚洲赛(贪心)
    题目大意:给定敌我两方士兵的数量和每一个士兵的攻击力和防守力,假设两个士兵对战。一方的攻击力大于等于还有一方的防守力。那么成功杀死,可能同归于尽
              问在我方能够全部杀死地方士兵的情况下,问我方能剩下的士兵最多是多少
    解题思路:这题去年在现场没有写出来== 首先要保证的是地方全部人都要被杀死,那么把我方士兵攻击力递减排序。敌方士兵防守力递减排序。枚举敌方的
              士兵。将我方全部攻击力大于其防守力的士兵入multiset。然后在当中选择第一个防守力大于当前敌方士兵攻击力的我方士兵,若没有满足的,删除
              我方防守力最低的士兵
    */
    #include <string.h>
    #include <stdio.h>
    #include <algorithm>
    #include <iostream>
    #include <set>
    using namespace std;
    typedef long long LL;
    const int maxn=100005;
    int m,n;
    struct note
    {
        int x,y;
        bool operator < (const note &other)const
        {
            return x>other.x;
        }
    }a[maxn],b[maxn];
    
    int main()
    {
        int T,tt=0;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d%d",&n,&m);
            for(int i=0;i<n;i++)
            {
                scanf("%d%d",&a[i].x,&a[i].y);
            }
            for(int j=0;j<m;j++)
            {
                scanf("%d%d",&b[j].y,&b[j].x);
            }
            sort(a,a+n);
            sort(b,b+m);
            multiset <int> st;
            int p=0,ans=n;
            for(int i=0;i<m;i++)
            {
                while(b[i].x<=a[p].x&&p<n)
                {
                    st.insert(a[p++].y);
                }
                if(st.empty())
                {
                    ans=-1;
                    break;
                }
                multiset<int>::iterator it=st.upper_bound(b[i].y);
                if(it==st.end())
                {
                    st.erase(st.begin());
                    ans--;
                }
                else
                    st.erase(it);
            }
            printf("Case #%d: %d
    ",++tt,ans);
        }
        return 0;
    }
    /**
    2
    3 2
    5 7
    7 3
    1 2
    4 4
    2 2
    2 1
    3 4
    1 10
    5 6
    */
    


  • 相关阅读:
    ORACLE表空间管理维护
    oracle表分区详解
    Jquery
    B
    A
    E
    字符串排成字典序,字符串数组
    命令,快捷键,配置
    第一个java程序
    A
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5208691.html
Copyright © 2011-2022 走看看