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\n",++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
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值