C. Two Seals
One 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?
The 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).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
2 2 2 1 2 2 1
4
4 10 9 2 3 1 1 5 10 9 11
56
3 10 10 6 6 7 7 20 5
0
In 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.
题意:给你一张a*b大小的纸,n个方形的印章 问你能不能在这张纸上同时盖下两个不同的印章 ,印章不能重叠 边缘可以紧挨 求符合条件的两个印章的最大面积和 都不符合条件输出0
下面n行是每个印章的长和宽
思路:暴力把所有选择情况试一遍 符合条件更新最大值
对于选择的两个印章 把它们的其中一条边贴合起来 有四种贴合方式 看下这四种贴合方式能不能盖到纸上
eg:对于a*b和x*y的两个印章 可以
把a,x贴一起 那么想要放下这两个印章就需要 一个max(a,x)*(b+y)的纸
把a,y贴一起 那么想要放下这两个印章就需要 一个max(a,y)*(b+x)的纸
把b,x贴一起 那么想要放下这两个印章就需要 一个max(b,x)*(a+y)的纸
把b,y贴一起 那么想要放下这两个印章就需要 一个max(b,y)*(a+x)的纸
对这四种情况依次询问 有一种符合情况就更新最大值 都不符合进行下一组测试
代码:
#include<cstdio>
#include<algorithm>
using namespace std;
int nu1,nu2;
bool solve(int x,int y,int a,int b)
{
int q,w;
q=max(x,a);
w=y+b;
if((q<=nu1&&w<=nu2)||(q<=nu2&&w<=nu1))
return 1;
else
{
q=max(x,b);
w=y+a;
if((q<=nu1&&w<=nu2)||(q<=nu2&&w<=nu1))
return 1;
else
{
q=max(y,b);
w=x+a;
if((q<=nu1&&w<=nu2)||(q<=nu2&&w<=nu1))
return 1;
else
{
q=max(y,a);
w=x+b;
if((q<=nu1&&w<=nu2)||(q<=nu2&&w<=nu1))
return 1;
}
}
}
return 0;
}
int main()
{
int n;
scanf("%d%d%d",&n,&nu1,&nu2);
int s[123][3];
for(int i=1;i<=n;i++)
{
scanf("%d%d",&s[i][1],&s[i][2]);
}
int Max=0;
for(int i=1;i<n;i++)
{
for(int j=i+1;j<=n;j++)
{
int flag=solve(s[i][1],s[i][2],s[j][1],s[j][2]);
if(flag)
{
int sum=s[i][1]*s[i][2]+s[j][1]*s[j][2];
if(sum>Max)
Max=sum;
}
}
}
printf("%d\n",Max);
return 0;
}