Educational Codeforces Round 26 Problem C

C. Two Seals
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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?

Input

The first line contains three integer numbers na and b (1 ≤ n, a, b ≤ 100).

Each of the next n lines contain two numbers xiyi (1 ≤ xi, yi ≤ 100).

Output

Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.

Examples
input
2 2 2
1 2
2 1
output
4
input
4 10 9
2 3
1 1
5 10
9 11
output
56
input
3 10 10
6 6
7 7
20 5
output
0
Note

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.

 题意:每个印章只能用一次,问能否盖两个印章。如果能,找出最大面积,不能输出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 }
原文地址:https://www.cnblogs.com/ISGuXing/p/7285084.html