Layer Cake cf
2015-10-26 16:03
429 查看
Layer Cake
time limit per test
6 seconds
memory limit per test
512 megabytes
input
standard input
output
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.
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 test(s)
input
output
input
output
Note
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.
time limit per test
6 seconds
memory limit per test
512 megabytes
input
standard input
output
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.
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 test(s)
input
5 5 12 1 1 4 6 6 4 4 6
output
96 6 4
input
2 100001 900000 900001 100000
output
180000000000 900000 100000
Note
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; }
相关文章推荐
- 068.Pointer 指针为什么分类型
- iOS开发UI篇—Quartz2D简单使用(一)
- php使用APC实现实时上传进度条功能
- 全面理解面向对象的 JavaScript
- keystone - Identity Federation介绍
- 3GPP TS 24.301 V12.4.0 中文版---1&2&3
- aixs2客户端调axis1服务
- ADT删除appcompat_v7文件
- 矩阵分解在推荐系统中的应用:NMF和经典SVD实战
- php模拟HTTP协议请求
- [转]nopcommerce之权限模块
- IIS7.5上的REST服务的Put操作发生HTTP Error 405.0 - Method Not Allowed 解决方法
- c#的const可以用于引用类型吗
- 闭包,作用域链,垃圾回收,内存泄露
- vijosP1053 Easy sssp
- MongoDB游标操作(4)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十五)
- 069.Pointer 指针作为函数的返回值
- LeetCode 51: N-Queens
- PCIe/RapidIO 控制器基于FPGA操作说明(PCIe 部分)