Layer Cake cf
6 seconds
512 megabytes
standard input
standard output
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 wereai 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.
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.
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.
5
5 12
1 1
4 6
6 4
4 6
96
6 4
2
100001 900000
900001 100000
180000000000
900000 100000
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.
题意:在给定蛋糕数量和长宽信息时,任取面包数量,让面包堆积成平行六边形即每一个面包的长和宽都相等(多了可以裁,求体积的最大值,每个面包的高度是1.
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm> using namespace std; #define maxn 4010 struct node
{
int x, y;
}P[maxn]; int X[maxn], Y[maxn]; int cmp(node a, node b)
{
if(a.x == b.x)
return a.y < b.y;
return a.x > b.x;
} int main()
{
int n, x, y, p, q; while(scanf("%d", &n) != EOF)
{
long long ans, sum = 0;
for(int i = 0; i < n; i++)
{
scanf("%d%d", &x, &y);
P[i].x = min(x, y);
P[i].y = max(x, y);
}
sort(P, P+n, cmp);
for(int i = 0; i < n; i++)
X[i] = P[i].x, Y[i] = P[i].y;
for(int i = 0; i < n; i++)
{
sort(Y, Y+i+1);
for(int j = 0; j <= i; j++)
{
ans = (long long)X[i] * Y[j] * (i-j+1);
if(ans > sum)
{
sum = ans;
p = X[i];
q = Y[j];
}
}
}
printf("%I64d\n%d %d\n", sum, p, q);
}
return 0;
}
Layer Cake cf的更多相关文章
- 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 ...
- #7 div2 B Layer Cake 造蛋糕 智商题+1
B - Layer Cake Time Limit:6000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u Sub ...
- CodeForces 589B Layer Cake (暴力)
题意:给定 n 个矩形是a*b的,问你把每一块都分成一样的,然后全放一块,高度都是1,体积最大是多少. 析:这个题,当时并没有完全读懂题意,而且也不怎么会做,没想到就是一个暴力,先排序,先从大的开始选 ...
- 【转载】ACM总结——dp专辑
感谢博主—— http://blog.csdn.net/cc_again?viewmode=list ---------- Accagain 2014年5月15日 动态规划一 ...
- 【DP专辑】ACM动态规划总结
转载请注明出处,谢谢. http://blog.csdn.net/cc_again?viewmode=list ---------- Accagain 2014年5月15日 ...
- CodeForces - 589B(暴力+排序)
Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...
- dp专题训练
****************************************************************************************** 动态规划 专题训练 ...
- 你真的了解分层架构吗?——写给被PetShop"毒害"的朋友们
一叶障目 .NET平台上的分层架构(很多朋友称其为“三层架构”),似乎是一个长盛不衰的话题.经常看到许多朋友对其进行分析.探讨.辩论甚至是抨击.笔者在仔细阅读了大量这方面文章后,认为许多朋友在分层架构 ...
- 【DP专辑】ACM动态规划总结(转)
http://blog.csdn.net/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少,多元性强, ...
随机推荐
- CVE 2019 0708 安装重启之后 可能造成 手动IP地址丢失.
1. 最近两天发现 更新了微软的CVE 2019-0708的补丁之后 之前设置的手动ip地址会变成 自动获取, 造成ip地址丢失.. 我昨天遇到两个, 今天同事又遇到一个.微软做补丁也不走心啊..
- 部署CM集群首次运行报错:Formatting the name directories of the current NameNode.
1. 报错提示 Formatting the name directories of the current NameNode. If the name directories are not emp ...
- roslyn\csc.exe
vs2019调试运行时提示roslyn\csc.exe错误时在nuget包管理器控制台里输入: Update-Package Microsoft.CodeDom.Providers.DotNetCo ...
- yii日志保存机制
一.修改yii框架的配置文件(main.php) 'log' => array( 'class' => 'CLogRouter', 'routes' => array( array( ...
- TestCase维护和思维导图
在软件整个生命周期中,测试应该尽早地开始,因为测试对象不只是程序,还有文档和数据,所以针对需求分析说明书.概要设计和详细设计说明书,测试如何快速理解项目需求,进行下一步的工作呢? 本人觉得,如果只是看 ...
- 使用CSDN-markdown编辑器粘贴代码块时崩溃问题解决
原因:代码段换行符失效,所有代码一行显示 解决方法:使用Chrome浏览器即可解决(使用Microsoft Edge会出现此问题) 效果展示: # _*_ coding:utf-8 _*_ impor ...
- 破解mysql
https://blog.csdn.net/lian_easel/article/details/78734240 破解mysql
- redis持久化机制与过期策略
RDB的持久化策略 (快照方式,默认持久化方式): 按照规则定时将内存中的数据同步到磁盘,它有以下4个触发场景. 1. 自己配置的快照规则 vim /redis/bin/ redis.conf:按照 ...
- 移动端布局的思考和rem的设置
如下方法如有不正确的地方,欢迎指正 前提: 设置稿750px 目标:40px = 1rem js设置方法:(小于等于750屏幕等比缩放) ;(function (doc, win, undefined ...
- vue 防抖和节流
函数防抖(debounce):当持续触发事件时,一定时间段内没有再触发事件,事件处理函数才会执行一次,如果设定的时间到来之前,又一次触发了事件,就重新开始延时. 函数节流(throttle):当持续触 ...