题意:给定 n 个矩形是a*b的,问你把每一块都分成一样的,然后全放一块,高度都是1,体积最大是多少。

析:这个题,当时并没有完全读懂题意,而且也不怎么会做,没想到就是一个暴力,先排序,先从大的开始选,如果大,那么数量少,如果小,数量就多,

用一个multiset来排序,这样时间复杂度会低一点,每一个都算一下比它的大矩阵的数量,然后算体积,不断更新,最大值。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <stack>
using namespace std ; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 4e3 + 5;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct node{
int x, y;
bool operator < (const node &p) const{
return x > p.x || (x == p.x && y < p.y);
}
};
node a[maxn];
multiset<int> sets; int main(){
while(scanf("%d", &n) == 1){
for(int i = 0; i < n; ++i){
scanf("%d %d", &a[i].x, &a[i].y);
if(a[i].x < a[i].y) swap(a[i].x, a[i].y);
}
sort(a, a+n);
sets.clear();
int num = 0, ansx, ansy;
LL ans = 0;
for(int i = 0; i < n; ++i){
sets.insert(a[i].y);
++num;
int cnt = 0;
for(auto &it : sets){
LL tmp = (LL)a[i].x * (LL)it * (LL)(num-cnt);
if(ans < tmp){
ans = tmp;
ansx = a[i].x;
ansy = it;
}
++cnt;
}
} printf("%I64d\n", ans);
printf("%d %d\n", ansx, ansy); }
return 0;
}

CodeForces 589B Layer Cake (暴力)的更多相关文章

  1. CodeForces - 589B(暴力+排序)

    Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...

  2. CodeForces - 589B

    题目链接:https://vjudge.net/contest/242578#problem/B Dasha decided to bake a big and tasty layer cake. I ...

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

  4. #7 div2 B Layer Cake 造蛋糕 智商题+1

    B - Layer Cake Time Limit:6000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Sub ...

  5. Layer Cake cf

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

  6. CodeForces - 589B(暴力)

    题目链接:http://codeforces.com/problemset/problem/589/B 题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分 ...

  7. codeforces 724B Batch Sort(暴力-列交换一次每行交换一次)

    题目链接:http://codeforces.com/problemset/problem/724/B 题目大意: 给出N*M矩阵,对于该矩阵有两种操作: (保证,每行输入的数是 1-m 之间的数且不 ...

  8. Uva 10167 - Birthday Cake 暴力枚举 随机

      Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys ...

  9. codeforces 897A Scarborough Fair 暴力签到

    codeforces 897A Scarborough Fair 题目链接: http://codeforces.com/problemset/problem/897/A 思路: 暴力大法好 代码: ...

随机推荐

  1. MemSQL start[c]up Round 2 - online version(DP)

    只有小写字母 那>=2600的直接找单字母串长度大于等于100的就可以了 <2600 的dp找最长回文串 #include <iostream> #include<cst ...

  2. Android中LayoutInflater的使用

    Inflater英文意思是膨胀,在Android中应该是扩展的意思吧. LayoutInflater 的作用类似于 findViewById(),不同点是LayoutInflater是用来找layou ...

  3. velocity加减运算注意格式 ,加减号的左右都要有空格

    velocity加减运算注意格式 ,加减号的左右都要有空格 #set( $left= $!biz.value - $vMUtils.getReturnMoney($!biz.billBuy) )

  4. IT玄幻小说

    职业 设计:菜鸟  美工<初级,中级,高级,资深>  设计师<初级,中级,高级,资深>  大神 前端:菜鸟  前端<初级,中级,高级,资深> 架构师<初级,中 ...

  5. Android 仿百度网页音乐播放器圆形图片转圈播放效果

    百度网页音乐播放器的效果  如下 : http://www.baidu.com/baidu?word=%E4%B8%80%E7%9B%B4%E5%BE%88%E5%AE%89%E9%9D%99& ...

  6. Android Studio进行NDK编程

  7. Using Open Source Static Libraries in Xcode 4

    Using Open Source Static Libraries in Xcode 4 Xcode 4.0.1 allows us to more easily create and use th ...

  8. ASP.NET MVC+Bootstrap个人博客之后台dataTable数据列表(五)

    jQuery  dataTables 插件是一个优秀的表格插件,是后台工程师的福音!它提供了针对数据表格的排序.浏览器分页.服务器分页.查询.格式化等功能.dataTables 官网也提供了大量的演示 ...

  9. jdbc:oracle:thin:@192.168.3.98:1521:orcl(详解)

    整理自互联网 一. jdbc:oracle:thin:@192.168.3.98:1521:orcljdbc:表示采用jdbc方式连接数据库oracle:表示连接的是oracle数据库thin:表示连 ...

  10. hdu 2544最短路——最短路的初次总结 UESTC 6th Programming Contest Online

    这是一道标准的模板题,所以拿来作为这一段时间学习最短路的总结题目. 题意很简单: 有多组输入数据,每组的第一行为两个整数n, m.表示共有n个节点,m条边. 接下来有m行,每行三个整数a, b, c. ...