【CodeForces】837C
来源:互联网 发布:c语言 void main 编辑:程序博客网 时间:2024/06/07 15:23
http://codeforces.com/problemset/problem/837/C
给定n,a,b,有n张海报,一张a*b的矩形纸张。
现要把2张海报贴到这张a*b的纸上面,海报必须在纸内不能露出纸外 且两张海报不能重叠 问你这两张海报面积之和的最大值
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;struct P{ int l; int w; int s;}p[105];int n,L,W;int sum;int ans=0;bool ok(int x1,int y1,int x2,int y2){ if ((x1<=x2&&y1<=y2)||(x1<=y2&&y1<=x2)){ return true; } else{ return false; }}bool cmp(struct P a,struct P b){ return a.s>b.s;}int main(){ cin >> n >> L >> W; if (L<W){ swap(L,W); } for (int i=0;i<n;i++){ cin >> p[i].l >> p[i].w; if (p[i].l<p[i].w){ swap(p[i].l,p[i].w); } p[i].s=p[i].l*p[i].w; } sort(p,p+n,cmp); for (int i=0;i<n-1;i++){ if (!ok(p[i].l,p[i].w,L,W)){ continue; } sum=p[i].s; int tL; int tW; if (p[i].l<=W){ tL=L-p[i].w; tW=W-p[i].l; for (int j=i+1;j<n;j++){ if (ok(p[j].l,p[j].w,tL,W)||ok(p[j].l,p[j].w,L,tW)){ ans=max(ans,sum+p[j].s); } } } tL=L-p[i].l; tW=W-p[i].w; for (int j=i+1;j<n;j++){ if (ok(p[j].l,p[j].w,tL,W)||ok(p[j].l,p[j].w,L,tW)){ ans=max(ans,sum+p[j].s); } } } cout << ans << endl;}
阅读全文
0 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
- HDU-2017"百度之星"程序设计大赛-初赛(B)-1002-Factory
- grep命令使用-正则表达式(zz)
- 向TreeSet集合中添加元素出现ClassCastException问题
- poj3013 Big Christmas Tree dijkstra
- Zabbix使用微信发送告警(附上Python代码)
- 【CodeForces】837C
- 欢迎使用CSDN-markdown编辑器
- Android与H5交互,数据不同步
- svn is already locked
- 详解冒泡排序及Python3代码实现
- VBMSFlexGrid控件选择并传值
- 2141数据结构实验之图论一:基于邻接矩阵的广度优先搜索遍历
- java基础学习总结——基础语法2
- C#快速开发PictureBox 图像控件