平常水题 Educational Codeforces Round 26 C (错误总结)

来源:互联网 发布:编译php strip tags 编辑:程序博客网 时间:2024/06/05 08:33

平常水题 Educational Codeforces Round 26 C

C. Two Seals
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 n, a and b (1 ≤ n, a, b ≤ 100).

Each of the next n lines contain two numbers xi, yi (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.

题意:有一个 a * b 的纸 ,要在 n 个大小为 xi * yi 的章中,挑取两个章出来,是它们盖在纸上的面积最大,两个章盖的位置不能重叠。

解题思路:思路很简单,给的数据不大,直接 n^2 暴力跑就行。写这篇只是为了提醒我想题时要全面,不要漏掉细节。

#include<cstdio>#include<iostream>#include<map>#include<queue>#include<cstring>#include<algorithm>#include<cmath>using namespace std;int x[200],y[200];int main(){    int n,a,b;    cin >> n >> a >> b;    if(a > b) swap(a,b);    for(int i = 1;i <= n;i++){        cin >> x[i] >> y[i];        if(x[i] > y[i]) swap(x[i],y[i]);    }    int sum,ma = 0;    for(int i = 1;i <= n;i++){        int k1,c1,k2,c2;        k1 = a - x[i],c1 = b;        if(k1 > c1) swap(k1,c1);        k2 = a,c2 = b - y[i];        if(k2 > c2) swap(k2,c2);        if(k1 < 0 || k2 < 0 || c1 < 0 || c2 < 0) continue;//先要保证这样放是合法的        for(int j = i + 1;j <= n;j++){            if((x[j] <= k1 && y[j] <= c1) || (x[j] <= k2 && y[j] <= c2)){                sum = x[i] * y[i] + x[j] * y[j];                ma = max(sum,ma);            }        }    }    for(int i = 1;i <= n;i++){        int k1,c1,k2,c2;        k1 = a - y[i],c1 = b;        if(k1 > c1) swap(k1,c1);        k2 = a,c2 = b - x[i];        if(k2 > c2) swap(k2,c2);        if(k1 < 0 || k2 < 0 || c1 < 0 || c2 < 0) continue;         for(int j = i + 1;j <= n;j++){            if((x[j] <= k1 && y[j] <= c1) || (x[j] <= k2 && y[j] <= c2)){                sum = x[i] * y[i] + x[j] * y[j];                ma = max(sum,ma);            }        }    }    cout << ma;}