codeforces 837 C
2017-08-15 17:33
267 查看
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 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
Output
Input
Output
Input
Output
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和个x*y大小的印章,纸张需要盖两个不同印章,求在不超出纸张大小的情况下盖在纸上的印章的最大面积
思路:
用贪心的思路,求出每个印章的面积然后排序,从大到小取,枚举所取印章与其它印章的两两组合再判断是否能将两个印章都盖上,取最大值。
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
struct Node
{
int x;
int y;
int ar;
}node[110];
int area[10010];
bool cmp(Node x,Node y)
{
return x.ar>y.ar;
}
bool cmp1(int x,int y)
{
return x>y;
}
int main()
{
int n,a,b;
while(scanf("%d%d%d",&n,&a,&b)!=EOF)
{
for(int i=0;i<n;i++){
scanf("%d%d",&node[i].x,&node[i].y);
node[i].ar=node[i].x*node[i].y;
}
sort(node,node+n,cmp);
int maxx=0;
for(int i=0;i<n;i++)
{
if(node[i].ar>a*b)
continue;
else if(max(node[i].x,node[i].y)>max(a,b)||min(node[i].x,node[i].y)>min(a,b))
continue;
int area=a*b;
area-=node[i].ar;
for(int j=i+1;j<n;j++)
{
if(node[j].ar>area)
continue;
else if(max(node[j].x,node[j].y)>max(a,b)||min(node[j].x,node[j].y)>min(a,b))
continue;
int d1=node[i].x+node[j].y;
int e1=max(node[i].y,node[j].x);
int d2=node[i].x+node[j].x;
int e2=max(node[i].y,node[j].y);
int d3=node[i].y+node[j].y;
int e3=max(node[j].x,node[i].x);
int d4=node[i].y+node[j].x;
int e4=max(node[i].x,node[j].y);
if((d1<=a&&e1<=b)||(d1<=b&&e1<=a)||(d2<=a&&e2<=b)||(d2<=b&&e2<=a)||(d3<=a&&e3<=b)||(d3<=b&&e3<=a)||(d4<=a&&e4<=b)||(d4<=b&&e4<=a))
if(node[i].ar+node[j].ar>maxx)
maxx=node[i].ar+node[j].ar;
}
}
printf("%d\n",maxx);
}
return 0;
}
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 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和个x*y大小的印章,纸张需要盖两个不同印章,求在不超出纸张大小的情况下盖在纸上的印章的最大面积
思路:
用贪心的思路,求出每个印章的面积然后排序,从大到小取,枚举所取印章与其它印章的两两组合再判断是否能将两个印章都盖上,取最大值。
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
struct Node
{
int x;
int y;
int ar;
}node[110];
int area[10010];
bool cmp(Node x,Node y)
{
return x.ar>y.ar;
}
bool cmp1(int x,int y)
{
return x>y;
}
int main()
{
int n,a,b;
while(scanf("%d%d%d",&n,&a,&b)!=EOF)
{
for(int i=0;i<n;i++){
scanf("%d%d",&node[i].x,&node[i].y);
node[i].ar=node[i].x*node[i].y;
}
sort(node,node+n,cmp);
int maxx=0;
for(int i=0;i<n;i++)
{
if(node[i].ar>a*b)
continue;
else if(max(node[i].x,node[i].y)>max(a,b)||min(node[i].x,node[i].y)>min(a,b))
continue;
int area=a*b;
area-=node[i].ar;
for(int j=i+1;j<n;j++)
{
if(node[j].ar>area)
continue;
else if(max(node[j].x,node[j].y)>max(a,b)||min(node[j].x,node[j].y)>min(a,b))
continue;
int d1=node[i].x+node[j].y;
int e1=max(node[i].y,node[j].x);
int d2=node[i].x+node[j].x;
int e2=max(node[i].y,node[j].y);
int d3=node[i].y+node[j].y;
int e3=max(node[j].x,node[i].x);
int d4=node[i].y+node[j].x;
int e4=max(node[i].x,node[j].y);
if((d1<=a&&e1<=b)||(d1<=b&&e1<=a)||(d2<=a&&e2<=b)||(d2<=b&&e2<=a)||(d3<=a&&e3<=b)||(d3<=b&&e3<=a)||(d4<=a&&e4<=b)||(d4<=b&&e4<=a))
if(node[i].ar+node[j].ar>maxx)
maxx=node[i].ar+node[j].ar;
}
}
printf("%d\n",maxx);
}
return 0;
}
相关文章推荐
- Codeforces 837 D Round Subset
- 【CodeForces】837B - Flag of Berland
- Codeforces-837D:Round Subset(DP)
- codeforces 320
- codeforces 263C
- codeforces 622C
- CodeForces - 868BC Qualification Rounds(思路)
- CodeForces - 540B School Marks (数学思维题 中位数)
- Codeforces 696B Puzzles 树形期望dp
- 【数论】codeforces 327C Magic five
- Codeforces 149D - Coloring Brackets(区间DP)
- [随机 Hash] Codeforces 799F Round #413 F. Beautiful fountains rows
- codeforces 869A The Artful Expedient
- Codeforces 106C Buns 【0-1背包】
- Codeforces 29C:Mail Stamps(STL的应用+DFS)
- codeforces A. Flipping Game 解题报告
- Codeforces 549E Sasha Circle
- Codeforces 810B Summer sell-off 题解
- Codeforces 846C Four Segments【思维+预处理+前缀和枚举】
- CodeForces 598D 【dfs+技巧省时】