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;
}
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;
}
相关文章推荐
- Raid管理详解
- 【static&extern,有心得】staitc在C中,修饰函数.(让我明白了,在include该文件后,则该文件的static也可见了)
- 2014 Asia Shanghai Regional Contest J
- 矩阵快速幂 CodeForces - 582B Once Again...
- codeforces 583B B. Once Again...(dp)
- HDU 4810 Wall Painting(组合数学)
- LightOJ 1282 Leading and Trailing
- Codeforces Round #323 (Div. 1) B. Once Again... 最长非严格递增子序列
- 搭建hibernate时 'hibernate.dialect' must be set when no Connection available错误
- testlink和maints的集成
- Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列
- maints使用
- codeforces 583 D. Once Again... (LIS + 贪心)
- [CareerCup] 10.3 Integer not Contain in the File 文件中不包含的数
- 1236 - Pairs Forming LCM (唯一分解定理加组合数学)
- 端口状态说明 LISTENING、ESTABLISHED、TIME_WAIT及CLOSE_WAIT
- Codeforces Round #323 (Div. 1) B. Once Again...
- coreseek windows下服务 FATAL: Tokenizer initialization failure 解决办法
- 嵌套的 CONTAINING_RECORD 宏
- 详细分析CONTAINING_RECORD宏