ACM-ICPC Live Archive Regionals 2014 >> Asia - Shanghai
Problems Soluble |
---|
J - World Cup |
I - Defeat the Enemy |
B - Rotation |
It is merely a problem about induction and deduction that trouble us mostly... The (m+1)th team has to be considered specially.
1 | /** |
Bipartite graph matching turns out to exceed the time limit.Use greedy strategy as estimated. Reflecting back upon the on-site period,the sort comparator can be considered correct.But the improper linear data structure failed to perform a "delete" operation. Now use `multiset` instead. Note that the optimal result doesn't necessarily have to do with that earlier or later one of the tribes battles. [code language="cpp"] /* * File: main.cpp * Author: semprathlon * * Created on December 2, 2015, 7:31 PM */
#include
#include
#include
#include
#include
using namespace std;
typedef pair<int,int> pr;
const int maxn=100010;
multiset
pr c[maxn],e[maxn];
bool cmp1(const pr &a,const pr &b){
return a.first>b.first;
}
bool cmp2(const pr &a,const pr &b){
return a.second>b.second;
}
int main() {
int T,cas=0;
scanf(“%d”,&T);
while(T–){
int n,m;
scanf(“%d%d”,&n,&m);
for(int i=0;i<n;i++){
int a,d;
scanf(“%d%d”,&a,&d);
c[i]=std::make_pair(a,d);
}
for(int i=0;i<m;i++){
int a,d;
scanf(“%d%d”,&a,&d);
e[i]=std::make_pair(a,d);
}
std::sort(c,c+n,cmp1);
std::sort(e,e+m,cmp2);
// for(int i=0;i<n;i++) printf(“%d,%d\n”,c[i].first,c[i].second);
// for(int i=0;i<m;i++) printf(“%d,%d\n”,e[i].first,e[i].second);
int ans=n;
st.clear();
for(int i=0,j=0;i<m;i++){
for(;j<n&&c[j].first>=e[i].second;j++)
st.insert(c[j].second);
if (st.empty()){
ans=-1;break;
}
multiset
if (it==st.end()){
st.erase(st.begin());
ans–;
}
else
st.erase(it);
}
printf(“Case #%d: %d\n”,++cas,ans);
}
return 0;
}
1 |
|
ACM-ICPC Live Archive Regionals 2014 >> Asia - Shanghai