Educational Codeforces Round 26:C. Two Seals
来源:互联网 发布:淘宝车商城 编辑:程序博客网 时间:2024/06/08 06:12
题目:
One very important person has a piece of paper in the form of a rectanglea × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the sizexi × 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 numbersxi,yi (1 ≤ xi, yi ≤ 100).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print0.
2 2 21 22 1
4
4 10 92 31 15 109 11
56
3 10 106 67 720 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.
思路:有两种情况 ,将第一张纸片横着放 or 竖着放,剩下的可以划分成3小块(再把其中相连的2块合成1块),判断第二张纸片能否不重叠地在放在矩形上。自己动手画个图就知道了。数据不打,暴力可过~
CODE:
#include<bits/stdc++.h>using namespace std;struct node{ int x,y;}q[105];int n,a,b;int fun(){ int i,j,x1,x2,x3,x4,y1,y2,y3,y4,maxr=0,flag; for(i=0;i<n;i++){ x1=q[i].x;y1=q[i].y; //纸片一 for(j=i+1;j<n;j++){ flag=0; //判断是否已选择一种方式存放 x2=q[j].x;y2=q[j].y; //纸片二 if(x1<=a&&y1<=b){ x3=a-x1;y3=b; x4=b-y1;y4=a; if(x2<=x3&&y2<=y3||x2<=x4&&y2<=y4||x2<=y3&&y2<=x3||x2<=y4&&y2<=x4){ maxr=max(maxr,x1*y1+x2*y2); flag=1; } } if(!flag){ if(x1<=b&&y1<=a){ x3=a-y1;y3=b; x4=b-x1;y4=a; if(x2<=x3&&y2<=y3||x2<=x4&&y2<=y4||x2<=y3&&y2<=x3||x2<=y4&&y2<=x4) maxr=max(maxr,x1*y1+x2*y2); } } } } return maxr;}int main(){ while(~scanf("%d%d%d",&n,&a,&b)){ if(a>b) swap(a,b); for(int i=0;i<n;i++){ scanf("%d%d",&q[i].x,&q[i].y); if(q[i].x>q[i].y) swap(q[i].x,q[i].y); } printf("%d\n",fun()); } return 0;}
- Educational Codeforces Round 26 C. Two Seals
- Educational Codeforces Round 26 C. Two Seals
- Educational Codeforces Round 26 C. Two Seals
- Educational Codeforces Round 26:C. Two Seals
- cf Educational Codeforces Round 26 C. Two Seals
- 【Codeforces 837C. Two Seals】
- Educational Codeforces Round 11 C (Two Pointers)
- Educational Codeforces Round 17-C Two strings
- Educational Codeforces Round 26 C
- [Educational Codeforces Round 17 C (762C)] Two strings
- Educational Codeforces Round 17 C. Two strings(二分)
- Educational Codeforces Round 27 C. Two TVs(模拟)
- Educational Codeforces Round 26 A—C
- Educational Codeforces Round 26
- Educational Codeforces Round 26
- Educational Codeforces Round 17 C && codeforces 762C C. Two strings(前缀后缀的妙用)
- Educational Codeforces Round 21 C
- Educational Codeforces Round 5 C
- keras中ImageDataGenerator用法
- http和https
- 543. Diameter of Binary Tree
- elasticsearch环境搭建
- ssh key生成及GIT远程仓库的建立
- Educational Codeforces Round 26:C. Two Seals
- nginx设置Tomcat反向代理,并静态资源分离
- java运行时找不到或无法加载主类的解决
- 数据结构之二叉树(链表)
- set容器
- 浅谈引用<一> Java中的对象和对象引用
- react-native初学跳坑
- 数据库设计中的一些技巧
- HDU6070-Dirt Ratio