CodeForces - 589B
题目链接:https://vjudge.net/contest/242578#problem/B
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.
Examples
5
5 12
1 1
4 6
6 4
4 6
96
6 4
2
100001 900000
900001 100000
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.
题目大意:输入n,代表蛋糕有n层,接下来n行代表每层蛋糕的长度宽度,每层蛋糕的高度都是1 ,长宽可以交换位置,问你长宽取值为多少时,切得的蛋糕体积最大
个人思路:由题可知,长宽的取值一定在已有的长宽中得到,这题其实就是暴力,枚举每一个长和每一个宽,取最大的那个就是答案了
看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
typedef long long ll;
using namespace std;
const ll mod=1e9+;
const int maxn=4e3+;
const int maxk=+;
const int maxx=1e4+;
const ll maxe=+;
#define INF 0x3f3f3f3f3f3f
struct cake
{
int w,l;
}a[maxn];
bool cmp(const cake a,const cake b)
{
return a.w<b.w;
}
int main()
{
ll n,ans=,answ,ansl;
int c[maxn];
cin>>n;
for(int i=;i<n;i++)
{
cin>>a[i].w>>a[i].l;
if(a[i].w>a[i].l)
swap(a[i].w,a[i].l);
}
sort(a,a+n,cmp);
for(int i=;i<n;i++)
{
int sum=;
for(int j=;j<n;j++)
{
if(a[j].l>=a[i].l)
{
c[sum++]=a[j].w;
}
}
for(int j=;j<sum;j++)
{
ll res;
res=(ll)a[i].l*c[j]*(sum-j);
if(res>ans)
{
ans=res;
answ=c[j];
ansl=a[i].l;
}
}
}
cout<<ans<<endl;
cout<<answ<<" "<<ansl<<endl;
return ;
}
CodeForces - 589B的更多相关文章
- CodeForces - 589B(暴力)
题目链接:http://codeforces.com/problemset/problem/589/B 题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分 ...
- CodeForces 589B Layer Cake (暴力)
题意:给定 n 个矩形是a*b的,问你把每一块都分成一样的,然后全放一块,高度都是1,体积最大是多少. 析:这个题,当时并没有完全读懂题意,而且也不怎么会做,没想到就是一个暴力,先排序,先从大的开始选 ...
- CodeForces - 589B(暴力+排序)
Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- 找工作-——网络IO
网络层 主要任务是把网络协议数据单元或分组从源计算机经过适当的路径发送到目的地计算机.从源计算机到目的计算机可能要经过若干个中间节点,这需要在通信子网中进行路由选择. 网络层与数据链路层有很大的差别, ...
- kafka之一:Windows上搭建Kafka运行环境
搭建环境 1. 安装JDK 1.1 安装文件:http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-213315 ...
- SpringMvc之参数绑定注解详解之三
2. @RequestHeader.@CookieValue @RequestHeader 注解,可以把Request请求header部分的值绑定到方法的参数上. 示例代码: 这是一个Request ...
- 关于hist
""" Demo of the histogram (hist) function with a few features. In addition to the bas ...
- HttpApplication 对象的创建过程及HttpModule过滤器的内部实现过程
最近通过Reflector学习了一下asp.net内部的原理,做做笔记,方便以后查阅. 先看下HttpApplication 对象的创建过程 从IHttpHandler applicationInst ...
- linux日常管理-rsync常用选项详解
-av 同步目录 写法 123/ /tmp/333/ 意思是把123下的文件同步到/tmp/333/下 结尾不加/ 只同步目录 两个目录一样的. //////////////////////// ...
- java 正则表达式 验证邮箱
import java.util.regex.Matcher; import java.util.regex.Pattern; public class demo1 { /**java正则表达式 * ...
- 【总结整理】javascript进阶学习(慕课网)
数组 数组是一个值的集合,每个值都有一个索引号,从0开始,每个索引都有一个相应的值,根据需要添加更多数值. 二维数组 二维数组 一维数组,我们看成一组盒子,每个盒子只能放一个内容. 一维数组的表示: ...
- redis 有用 Sorted-Set 应用场景
1.1.1Set数据类型的 使用场景 1.可以使用Redis的Set数据类型跟踪一些唯一性数据,比如访问某一博客的唯一IP地址信息.对于此场景,我们仅需在每次访问该博客时将访问者的IP存入Redis中 ...
- ASP.NET jquery 获取服务器控件ID
一般方法: jQuery("#txtUserName").val(); 如果页面加载了母版页或者自定义控件:该页面的ID有可能会被篡改(可能是因为避免控件ID冲突的机制),因此强烈 ...