HDU 4268 Alice and Bob 贪心STL O(nlogn)
2015-03-07 15:04
363 查看
B-AliceandBob
TimeLimit:5000MSMemoryLimit:32768KB64bitIOFormat:%I64d&%I64u
Description
AliceandBob'sgameneverends.Today,theyintroduceanewgame.Inthisgame,bothofthemhaveNdifferentrectangularcardsrespectively.
AlicewantstousehiscardstocoverBob's.ThecardAcancoverthecardBiftheheightofAisnotsmallerthanBandthewidthofAisnotsmallerthanB.Asthebestprogrammer,youareaskedtocomputethemaximalnumberofBob'scardsthatAlicecancover.
Pleasepayattentionthateachcardcanbeusedonlyonceandthecardscannotberotated.
Input
ThefirstlineoftheinputisanumberT(T<=40)whichmeansthenumberoftestcases.
Foreachcase,thefirstlineisanumberNwhichmeansthe
numberofcardsthatAliceandBobhaverespectively.Eachofthe
followingN(N<=100,000)linescontainstwointegersh(h<=
1,000,000,000)andw(w<=1,000,000,000)whichmeanstheheightand
widthofAlice'scard,thenthefollowingNlinesmeansthatofBob's.
Output
Foreachtestcase,outputananswerusingonelinewhichcontainsjustonenumber.
SampleInput
2
2
12
34
23
45
3
23
57
68
41
25
34
SampleOutput
12
题意:10W个数据,A有n张牌,B有n张牌,然后如果a.x>=b.x&&a.y>=b.y那么A就可以覆盖B
然后问你最多覆盖多少张
题解:暴力非常好想,O(n^2)跑一发就是,但是会T
那么我们就二分查找,或者用STL就好
TimeLimit:5000MSMemoryLimit:32768KB64bitIOFormat:%I64d&%I64u
Description
AliceandBob'sgameneverends.Today,theyintroduceanewgame.Inthisgame,bothofthemhaveNdifferentrectangularcardsrespectively.
AlicewantstousehiscardstocoverBob's.ThecardAcancoverthecardBiftheheightofAisnotsmallerthanBandthewidthofAisnotsmallerthanB.Asthebestprogrammer,youareaskedtocomputethemaximalnumberofBob'scardsthatAlicecancover.
Pleasepayattentionthateachcardcanbeusedonlyonceandthecardscannotberotated.
Input
ThefirstlineoftheinputisanumberT(T<=40)whichmeansthenumberoftestcases.
Foreachcase,thefirstlineisanumberNwhichmeansthe
numberofcardsthatAliceandBobhaverespectively.Eachofthe
followingN(N<=100,000)linescontainstwointegersh(h<=
1,000,000,000)andw(w<=1,000,000,000)whichmeanstheheightand
widthofAlice'scard,thenthefollowingNlinesmeansthatofBob's.
Output
Foreachtestcase,outputananswerusingonelinewhichcontainsjustonenumber.
SampleInput
2
2
12
34
23
45
3
23
57
68
41
25
34
SampleOutput
12
题意:10W个数据,A有n张牌,B有n张牌,然后如果a.x>=b.x&&a.y>=b.y那么A就可以覆盖B
然后问你最多覆盖多少张
题解:暴力非常好想,O(n^2)跑一发就是,但是会T
那么我们就二分查找,或者用STL就好
multiset<int>myset; multiset<int>::iteratorit; constintmaxn=200000; structnode { intx,y; booloperator<(constnode&b)const { returnx<b.x; } }a[maxn],b[maxn]; intmain() { intsec,n; scanf("%d",&sec); for(intz=1;z<=sec;z++) { myset.clear(); scanf("%d",&n); for(inti=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y); for(inti=1;i<=n;i++) scanf("%d%d",&b[i].x,&b[i].y); sort(a+1,a+1+n);//按x从小到大排序 sort(b+1,b+1+n);//按x从小到大排序 intj=1;intans=0;//j是一个指向B数组位置的指针 for(inti=1;i<=n;i++) { while(j<=n&&b[j].x<=a[i].x) { myset.insert(b[j].y); j++; } it=myset.upper_bound(a[i].y); if(myset.size()>0&&it!=myset.begin())it--; if(myset.size()>0&&(*it)<=a[i].y) { ans++; myset.erase(it); } } printf("%d\n",ans); } return0; }
相关文章推荐
- hdu 4268 Alice and Bob(STL贪心)
- HDU 4268 Alice and Bob(贪心+STL)
- 贪心,STL,multiset(Alice and Bob,HDU 4268)
- Alice and Bob----HDU_4268----贪心+STL
- HDU 4268 Alice and Bob(贪心+STL)
- HDU 4268 Alice and Bob(贪心)
- hdu 4268 Alice and Bob矩形覆盖(贪心)
- HDU 4268-Alice and Bob-贪心
- HDU 4268 Alice and Bob (贪心)
- HDUoj 4268 Alice and Bob ( STL二分贪心
- 【set+贪心】HDU 4268——Alice and Bob
- HDU 4268 Alice and Bob(贪心+Multiset的应用)
- hdu 4268 Alice and Bob(贪心+multiset)
- hdu 4268 Alice and Bob(STL版)
- HDU 4268 Alice and Bob(贪心+multiset)
- HDU 4268-Alice and Bob( STL: set)
- HDU 4268 Alice and Bob(贪心)
- hdu 4268 Alice and Bob(lower_bound+贪心)
- hdu 4268 Alice and Bob(贪心+multiset+二分)
- hdu 4268 Alice and Bob(贪心)