您的位置:首页 > 大数据 > 人工智能

2014 Asia Shanghai Regional Contest H

2015-10-05 21:36 411 查看
Long long ago there is a strong tribe living on the earth. They always have wars and eonquer others.
One day, there is another tribe become their target. The strong tribe has decide to terminate them!

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#define LL long long
#define WW freopen("in.txt","r",stdin)
#define RR freopen("out.txt","w",stdout)
#define INF 0x3f3f3f3f

using namespace std;
const int maxn = 100100;

class My
{
public:

int At,Df;
bool operator < (const struct My a)const
{
return At == a.At ? Df > a.Df : At > a.At;
}
};

class Enemy
{
public:
int At,Df;
bool operator < (const struct Enemy a)const
{
return Df == a.Df ? At > a.At : Df > a.Df;
}
};

My a[maxn];
Enemy b[maxn];

int main()
{
int T;
scanf("%d",&T);
int cas = 0;
while(T--)
{
int n,m;

scanf("%d%d",&n,&m);

for(int i=0;i<n;i++)
{
scanf("%d %d",&a[i].At,&a[i].Df);
}
for(int i=0;i<m;i++)
{
scanf("%d %d",&b[i].At,&b[i].Df);
}
sort(a,a+n);
sort(b,b+m);

multiset<int > S;
int j = 0;
int num = n;
bool flag = true;
for(int i=0;i<m;i++)
{
while(j < n && a[j].At >= b[i].Df)
S.insert(a[j++].Df);
if(S.empty())
{
flag = false;
break;
}
multiset<int >::iterator it;
it = S.lower_bound(b[i].At+1);
if(it == S.end())
{
S.erase(S.begin());
num--;
}
else
S.erase(it);
}
if(!flag)
printf("Case #%d: -1\n",++cas);
else
printf("Case #%d: %d\n",++cas,num);

}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: