UVA LA 7146 2014上海亚洲赛(贪心)

来源:互联网 发布:windows主进程rundll32 编辑:程序博客网 时间:2024/05/16 08:52

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\n",++tt,ans);    }    return 0;}/**23 25 77 31 24 42 22 13 41 105 6*/


0 0