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竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少,多元性强, ...
随机推荐
- Centos 安装Jenkins的坎坷
安装Jenkins(简单复制即可) wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.rep ...
- 第十一周总结 继承、this和super的区别和用法、方法的重写和重载
一.继承 1.子类继承父类,通过一个关键字 extends 2.子类的对象可以调用父类中的(public protected)属性和方法 当作自己的来使用 3.子类可以添加自己独有的属性和方法 4.子 ...
- 第五周课程总结&试验报告(三
实验三 String类的应用 实验目的 掌握类String类的使用: 学会使用JDK帮助文档: 实验内容 1.已知字符串:"this is a test of java".按要求执 ...
- FHJ学长的心愿 QDUOJ 数论
FHJ学长的心愿 原题链接,点我进去 题意 给你一个数N,让你求在\[C^{0}_{n} \ C^{1}_{n}\ C^{2}_{n}\ \dots \ C^{n}_{n}\]中有几个组合数是奇数. ...
- 大div中,三个小div水平居中
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- TMS320F28335——下载程序到flash中
一.让CCS软件支持Flash烧写 添加F28335.cmd文件 如图屏蔽掉25335_RAM_lnk.cmd 2.支持从Flash中拷贝文件到RAM中 添加DSP2832x_MemCopy.c 在主 ...
- ISC2016训练赛 phrackCTF--Smali
测试文件:https://static2.ichunqiu.com/icq/resources/fileupload/phrackCTF/REVERSE/Crackme.smali 参考资料:http ...
- Vue框架前言
Vue框架 Vue 框架: 官网 vue框架:渐进式JavaScript框架 vue一个环境:可以只控制页面中一个标签.可以控制一组标签.可以控制整个页面.可以控制整个项目 vue可以根据实际需求,选 ...
- setTimeout、Promise、Async/Await 的执行顺序
问题描述:以下这段代码的执行结果 async function async1() { console.log('async1 start'); await async2(); console.log( ...
- 流畅的Python (Fluent Python) —— 第二部分01
2.1 内置序列类型概览 Python 标准库用 C 实现了丰富的序列类型,列举如下. 容器序列 list. tuple 和 collections.deque 这些序列能存放不同类型的数据. 扁平序 ...