B - Layer Cake

Time Limit:6000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u

Submit Status

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

Input
5 12
1 1
4 6
6 4
4 6
Output
6 4
Input
100001 900000
900001 100000
Output
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个矩形n(1 ≤ n ≤ 4000) ,矩形可以削减,从中选出k个,(可以)削减后,保证k个矩形面积一样,求k*矩形面积的最大值

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf =0x7f7f7f7f;
const double pi=acos(-1);
const int maxn=20000+10; int n,b[maxn];
struct node{
int x,y;
bool operator<(const node &a) const
{return this->x<a.x;}
}ne[maxn]; int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
scanf("%d %d",&ne[i].x,&ne[i].y);
if(ne[i].x>ne[i].y) swap(ne[i].x,ne[i].y);
}
sort(ne+1,ne+n+1);
int l,w,cnt=0;ll ans=0;
for(int i=n;i>=1;i--)
{
b[++cnt]=ne[i].y;
sort(b+1,b+cnt+1);
for(int j=1;j<=cnt;j++)
if(ans<((ll)ne[i].x)*b[j]*(cnt-j+1))
{
ans=((ll)ne[i].x)*b[j]*(cnt-j+1);
l=ne[i].x;
w=b[j];
}
}
if(l<w) swap(l,w);
printf("%lld\n%d %d\n",ans,l,w);
}
return 0;
}

比赛分析:

比赛时想到了需要枚举所有的边的组合(n^2),然后还想到了应该算出这种组合下的矩形的个数(O(n)),但是这样

复杂度是n^3啊,显然需要降低,然后就一直在纠结着怎么用二分求出矩形个数,,,但是二分出来时错的,因为虽然是先按x排序,再

按y排序,那么当二分出来一个点后,很可能x比该点大的点的y值不满足条件,那么这个点就不能计入.......

纠错:

我们先将x排好序后,然后从大到小枚举x(O(n)),将所有x>=当前枚举的x的点的y值从小到大排排序(nlogn),然后再

排好序的y上进行枚举,其实就是通过两次排序筛选出x'>=x,y'>=y的值得矩形个数

#7 div2 B Layer Cake 造蛋糕 智商题+1的更多相关文章

  1. 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 ...

  2. Layer Cake cf

    Layer Cake time limit per test 6 seconds memory limit per test 512 megabytes input standard input ou ...

  3. CodeForces 589B Layer Cake (暴力)

    题意:给定 n 个矩形是a*b的,问你把每一块都分成一样的,然后全放一块,高度都是1,体积最大是多少. 析:这个题,当时并没有完全读懂题意,而且也不怎么会做,没想到就是一个暴力,先排序,先从大的开始选 ...

  4. TTTTTTTTTTTTTTTTTTT CF 银行转账 图论 智商题

    C. Money Transfers time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. bzoj 1318: [Spoj744] Longest Permutation 智商题

    1318: [Spoj744] Longest Permutation Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 361  Solved: 215 ...

  6. zoj 3647 智商题

    此题就是求格点中三角形的个数. 就是找出三点不共线的个数. n*m的矩形中有(n+1)*(m+1)个格点. 选出三个点的总个数为:C((n+1)*(m+1),3). 减掉共线的情况就是答案了. 首先是 ...

  7. 【20181102T2】飞越行星带【智商题+最小瓶颈路】

    题面 [正解] 一眼不可做啊 --相当于求路线上穿过的点最小距离最大 最小最大--二分啊 现在相当于给一个直径,要判断这个直径是否能从左边穿到右边 我们可以在距离不超过直径的点连一条边,\(y=0\) ...

  8. codeforces round 472(DIV2)D Riverside Curio题解(思维题)

    题目传送门:http://codeforces.com/contest/957/problem/D 题意大致是这样的:有一个水池,每天都有一个水位(一个整数).每天都会在这一天的水位上划线(如果这个水 ...

  9. agc016C - +/- Rectangle(构造 智商题)

    题意 题目链接 Sol 我的思路:直接按样例一的方法构造,若$h \times w$完全被$N \times M$包含显然无解 emm,wa了一发之后发现有反例:1 4 1 3 我的会输出[1 1 - ...

随机推荐

  1. django 中 null=True 和 blank=True的区别!

    null 是针对数据库而言,如果 null=True, 表示数据库的该字段可以为空,即在Null字段显示为YES. blank 是针对表单的,如果 blank=True,表示你的前端表单填写该字段的时 ...

  2. 怎样理解 MVVM ( Model-View-ViewModel ) ?

    MVVM 的 产生 / 实现 / 发展 可以写一篇很长的博客了, 这里仅写一下个人对 MVVM的一些肤浅的认识. 1. 在 没有 MVVM 之前, 前端可以说是 jQuery一把梭 , jQuery ...

  3. GNU g++常用编译选项用法

    GNU g++常用编译选项用法 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/30686/showart_1210761.html GCC ...

  4. char 、 unsigned char 互相转化

    1. 利用unsigned char (即uchar) 保存char 数据  ,直接赋值即可 unsigned char uc; char c=-33; uc= c; cout<<(int ...

  5. WebStrom 中文显示异常中文变样乱码

    问题描述 WebStorm 编辑文件时中文显示异常,大小不一 菜单栏字体需要更换 解决方法 修改编辑器字体 菜单栏默认字体取消 设置效果 编辑文件时中英文显示 菜单栏 其他相关 关于编码格式,这里未做 ...

  6. tp中的u方法

    个人总结以免忘记 在模板中的使用{:U('地址', '参数'…)} <!--在模板中使用U方法 --> <a href="{:U('News/index')}" ...

  7. 自定义事件 Event 、CustomEvent的使用

    通过Event和dispathEvents触发自定义事件 <span id="btn">获取</span> <script> var event ...

  8. Java学习笔记【九、集合框架】

    集合框架设计的目标: 高性能. 允许不同类型的集合,以类似的方式工作,有互操作性. 对一个集合的扩展和适应必须简单. 集合框架包含: 接口:代表集合的抽象数据类型. 实现(类):具体实现(ArrayL ...

  9. nginx的反向代理的优势,特点于原理(一)

    说到反向代理,首先先说一下反向代理的概念 反向代理(Reverse Proxy)方式是指以代理服务器来接受客户端的连接请求,然后将请求转发给网络上的web服务器(可能是apache,nginx,tom ...

  10. AD软件中可视栅格 捕捉栅格 电气栅格的功能和设置详解

    AD16的栅格设置 AD16系统共有3种栅格:可视栅格.电气栅格.捕捉栅格. Snap:捕获栅格,如果设定值是10mil,鼠标的光标拖动零件引脚,距离可视栅格在10mil范围之内时,零件引脚自动的准确 ...