首页 > 代码库 > hdu 4268 Alice and Bob
hdu 4268 Alice and Bob
Alice and Bob
Time Limit : 10000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 5 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Alice and Bob‘s game never ends. Today, they introduce a new game. In this game, both of them have N different rectangular cards respectively. Alice wants to use his cards to cover Bob‘s. The card A can cover the card B if the height of A is not smaller than B and the width of A is not smaller than B. As the best programmer, you are asked to compute the maximal number of Bob‘s cards that Alice can cover.
Please pay attention that each card can be used only once and the cards cannot be rotated.
Please pay attention that each card can be used only once and the cards cannot be rotated.
Input
The first line of the input is a number T (T <= 40) which means the number of test cases.
For each case, the first line is a number N which means the number of cards that Alice and Bob have respectively. Each of the following N (N <= 100,000) lines contains two integers h (h <= 1,000,000,000) and w (w <= 1,000,000,000) which means the height and width of Alice‘s card, then the following N lines means that of Bob‘s.
For each case, the first line is a number N which means the number of cards that Alice and Bob have respectively. Each of the following N (N <= 100,000) lines contains two integers h (h <= 1,000,000,000) and w (w <= 1,000,000,000) which means the height and width of Alice‘s card, then the following N lines means that of Bob‘s.
Output
For each test case, output an answer using one line which contains just one number.
Sample Input
221 23 42 34 532 35 76 84 12 53 4
Sample Output
12
题意:两组卡片,第一组的某一张卡片的长并且宽大于等于第二组某一张卡片的长和宽(x,y), 加1;
先sort排序下,利用multiset去存第二组的y,multiset容器可以存相同的元素
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cmath> 5 #include<cstring> 6 #include<set> 7 #include<map> 8 #include<queue> 9 #include<vector>10 //#define INF 0x3f3f3f3f11 #define N 10000512 typedef long long ll;13 using namespace std;14 struct node{15 int x;16 int y;17 }a[N],b[N];18 bool cmp(node aa,node bb){19 if(aa.x==bb.x){20 return aa.y<bb.y;21 }22 else23 return aa.x<bb.x;24 }25 int main()26 {27 int t,n;28 scanf("%d",&t);29 int i,j;30 while(t--)31 {32 scanf("%d",&n);33 for(i=0;i<n;i++)34 scanf("%d%d",&a[i].x,&a[i].y);35 sort(a,a+n,cmp);36 for(i=0;i<n;i++)37 scanf("%d%d",&b[i].x,&b[i].y);38 sort(b,b+n,cmp);39 multiset<ll>st;40 multiset<ll>::iterator it;41 int ans=0;42 st.clear();43 j=0;44 for(i=0;i<n;i++){45 while(a[i].x>=b[j].x&&j<n){46 st.insert(b[j].y);47 j++;48 }49 if(st.empty())50 continue;51 it=st.upper_bound(a[i].y);52 if(it!=st.begin())53 {54 it--;55 ans++;56 st.erase(it);57 }58 }59 printf("%d\n",ans);60 }61 }
hdu 4268 Alice and Bob
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。