C. Two Sealstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
InputThe first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
OutputPrint the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examplesinput2 2 2
1 2
2 1output4input4 10 9
2 3
1 1
5 10
9 11output56input3 10 10
6 6
7 7
20 5output0NoteIn the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
题意:每个印章只能用一次,问能否盖两个印章。如果能,找出最大面积,不能输出0.
思路:暴力枚举。
ps:开始用了排序,后来发现sort写的有问题。直接暴力就AC了。
1 #include<iostream> 2 #include<stdio.h> 3 #include<algorithm> 4 using namespace std; 5 struct Node{ 6 int x,y,s; 7 }an[105]; 8 int main(){ 9 int n,a,b; 10 cin>>n>>a>>b; 11 for(int i=0;i<n;i++){ 12 scanf("%d %d",&an[i].x,&an[i].y); 13 an[i].s=an[i].x*an[i].y; 14 } 15 int mx=0; 16 for(int i=0;i<n-1;i++){ 17 for(int j=i+1;j<n;j++){ 18 if(an[i].x+an[j].x<=a&&an[i].y<=b&&an[j].y<=b&&an[i].s+an[j].s<=a*b){ 19 mx=max(mx,an[i].s+an[j].s); 20 }else if(an[i].x+an[j].y<=a&&an[i].y<=b&&an[j].x<=b&&an[i].s+an[j].s<=a*b){ 21 mx=max(mx,an[i].s+an[j].s); 22 }else if(an[i].y+an[j].x<=a&&an[i].x<=b&&an[j].y<=b&&an[i].s+an[j].s<=a*b){ 23 mx=max(mx,an[i].s+an[j].s); 24 }else if(an[i].y+an[j].y<=a&&an[i].x<=b&&an[j].x<=b&&an[i].s+an[j].s<=a*b){ 25 mx=max(mx,an[i].s+an[j].s); 26 }else if(an[i].x+an[j].x<=b&&an[i].y<=a&&an[j].y<=a&&an[i].s+an[j].s<=a*b){ 27 mx=max(mx,an[i].s+an[j].s); 28 }else if(an[i].x+an[j].y<=b&&an[i].y<=a&&an[j].x<=a&&an[i].s+an[j].s<=a*b){ 29 mx=max(mx,an[i].s+an[j].s); 30 }else if(an[i].y+an[j].x<=b&&an[i].x<=a&&an[j].y<=a&&an[i].s+an[j].s<=a*b){ 31 mx=max(mx,an[i].s+an[j].s); 32 }else if(an[i].y+an[j].y<=b&&an[i].x<=a&&an[j].x<=a&&an[i].s+an[j].s<=a*b){ 33 mx=max(mx,an[i].s+an[j].s); 34 }else{} 35 } 36 } 37 cout<<mx<<endl; 38 return 0; 39 }