2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest, B. Layer Cake
Description
Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n rectangular cake layers. The length and the width of the i-th cake layer were ai and bi respectively, while the height of each cake layer was equal to one.
From a cooking book Dasha learned that a cake must have a form of a rectangular parallelepiped constructed from cake layers of the same sizes.
Dasha decided to bake the biggest possible cake from the bought cake layers (possibly, using only some of them). It means that she wants the volume of the cake to be as big as possible. To reach this goal, Dasha can cut rectangular pieces out of the bought cake layers. She always cuts cake layers in such a way that cutting lines are parallel to the edges of that cake layer. Dasha isn't very good at geometry, so after cutting out a piece from the original cake layer, she throws away the remaining part of it. Also she can rotate a cake layer in the horizontal plane (swap its width and length).
Dasha wants her cake to be constructed as a stack of cake layers of the same sizes. Each layer of the resulting cake should be made out of only one cake layer (the original one or cut out from the original cake layer).
Help Dasha to calculate the maximum possible volume of the cake she can bake using given cake layers.
Input
The first line contains an integer n(1 ≤ n ≤ 4000) — the number of cake layers that Dasha can use.
Each of the following n lines contains two integer numbers ai and bi(1 ≤ ai, bi ≤ 106) — the length and the width of i-th cake layer respectively.
Output
The first line of the output should contain the maximum volume of cake that can be baked using given layers.
The second line of the output should contain the length and the width of the resulting cake. If there are many solutions with maximum possible volume, print any of them.
Sample Input
5
5 12
1 1
4 6
6 4
4 6
96
6 4
2
100001 900000
900001 100000
180000000000
900000 100000
Hint
In the first example Dasha doesn't use the second cake layer. She cuts 4 × 6 rectangle from the first cake layer and she uses other cake layers as is.
In the second example Dasha cuts off slightly from the both cake layers.
题意:给你n个高度为1的蛋糕,分别有长和宽; 让你将这些蛋糕垒起来平行于边切,使得每块蛋糕长宽相同;求最大体积,输出体积和长、宽;
思路:输入时统一长和宽(宽小于长),然后按照宽从小到大排序,两重循环,i=0~n-1,j=0~n-1,计数vec[0~j].second>=ves[i].second有多少,
记为num,mp[i][j]=num,由此可以看出mp[i][j]表示,以ves[i].second为宽,以ves[j].first为长的蛋糕层的个数,那么以ves[i].second为宽,以ves[j].first为长的蛋糕的体积最大为;ves[i].second*ves[j].first*mp[i][j];最后两层循环遍历,计算以每个mp[i][j]为蛋糕大小的体积,找出最大值;
代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int maxn=;
typedef long long LL;
int mp[maxn][maxn];
int main()
{
int n;
LL x,y;
while(cin>>n)
{
memset(mp, , sizeof(mp));
vector< pair<LL ,LL> >vec;
for(int i=; i<n; i++)
{
cin>>x>>y;
if(x>y) swap(x, y);
vec.push_back(make_pair(x, y));
}
sort(vec.begin(), vec.end());
for(int i=n-; i>=; i--)
{
int num=;
for(int j=n-;j>=;j--)
{
if(vec[j].second>=vec[i].second)
num++;
mp[i][j]=num;
}
}
LL ans=,ansx=,ansy=;
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
LL x=vec[i].first;
LL y =vec[j].second;
LL sum=x*y;
LL tot=sum*mp[j][i];
if(ans < tot)
{
ans=tot;
ansx=x;
ansy=y;
}
}
}
cout<<ans<<endl;
cout<<ansx<<" "<<ansy<<endl;
}
return ;
}
2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest, B. Layer Cake的更多相关文章
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution
从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
- codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...
- 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)
i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution
A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...
- 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing
[链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...
随机推荐
- 点击弹出 +1放大效果 -- jQuery插件
20140110更新: <!doctype html> <html> <head> <meta charset="UTF-8"> & ...
- VC中使用ATL库实现正则表达式匹配(ADODB::Error)
1. 确保项目属性中ATL使用处于打开状态. 如VS中项目属性常规—ATL使用—静态链接到ATL 2. 在使用时加上头文件 #include "atlrx.h" 3. 使用示例代码 ...
- 一段时间没上来了,看到有很多网友对OWA感兴趣,因为所在公司发展方向的原因,没有太多时间继续深入研究OWA,敬请见谅
一段时间没上来了,看到有很多网友对OWA感兴趣,因为所在公司发展方向的原因,没有太多时间继续深入研究OWA,敬请见谅
- 实例学习Backbone.js(一)
前面有两篇文章介绍了Backbone的model.collection和view,那么接下来我想用一个完整的Demo来记录我学习的过程, 单页操作,实现数据的增删改,后台使用json做数据库,通过re ...
- VMware的使用
1.问题的提出 现在所有的组装台式机,均以64位操作系统作为平台 而且USB接口均以USB3.0默认 windows7 64位和windows 10 64位是主流 那么建立在windo ...
- Qt Style Sheets Examples——定制前景色和背景色
例子取自:http://qt-project.org/doc/qt-4.8/stylesheet-examples.html 以lineEdit为例 (1)设置某个lineEdit的背景色为黄色 li ...
- Android UI 优化——使用HierarchyViewer工具
先说些题外话,希望路过的各位支持,博主有幸成为2013年度博客之星的候选人,期待你的一票,谢谢. 投票猛击: http://vote.blog.csdn.net/blogstaritem/blogst ...
- JavaScript之Array常用函数汇总
[20141121]JavaScript之Array常用功能汇总 *:first-child { margin-top: 0 !important; } body>*:last-child { ...
- 关于全局唯一ID生成方法
引:最近业务开发过程中需要涉及到全局唯一ID生成.之前零零总总的收集过一些相关资料,特此整理以便后用 本博客已经迁移至:http://cenalulu.github.io/ 本篇博文已经迁移,阅读全文 ...
- 配置visual studio code进行asp.net core rc2的开发
1.安装.net core sdk https://github.com/dotnet/cli#installers-and-binaries,根据你的系统选择下载. 2.下载vscode的C#扩展插 ...