codeforces 837 C
来源:互联网 发布:淘宝网团购 编辑:程序博客网 时间:2024/06/05 04:56
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 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.
题意:
给你一个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 837C(暴力)
- 【CodeForces】837C
- codeforces 837 C
- 【Codeforces 837C. Two Seals】
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- CodeForces 156C Cipher
- codeforces 148 div2 C
- codeforces 242C
- Codeforces-234C Weather
- codeforces 106C Buns
- codeforces 158C
- 回文串(最长前缀/最长子串)
- 算法学习(二)——快速排序(Java实现)
- 最好的8个 Java RESTful 框架
- numpy入门——数据分割
- python基础
- codeforces 837 C
- Git使用教程之本地仓库的基本操作
- 限时抢购秒杀系统架构分析与实战
- 阻止a链接跳转方法总结
- response.setContentType与 request.setCharacterEncoding 区别
- UVA 156
- 利用setMouseCallback函数实现鼠标对图片窗口的操作!
- phpcms v9 去掉编辑器上传图片的宽高样式
- 配置opencv和VS2013