CodeForces 589B-Layer Cake-暴力模拟

刚看到这个题的想法是建图搜路,写出来了才发现这个做法不行,不能把每一个矩形看成不可分的点,因为最终的矩形可能两条边出现在不同矩形里。

后来看了题解才明白直接暴力就行。关键是明白最终的矩形两条边都在所给矩形中出现。

 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <cstring>
 4
 5 using namespace std;
 6
 7 typedef long long ll;
 8 const int INF = 0x3f3f3f3f;
 9 const int maxn = 4e3+10;
10 struct cake
11 {
12     int w,l;
13     cake(){}
14     bool operator < (const cake &b) const
15     {
16         return l > b.l;
17     }
18 }ck[maxn];
19
20 int N,len[maxn];
21
22 int main()
23 {
24     scanf("%d",&N);
25
26     for(int i=0;i<N;i++)
27     {
28         scanf("%d%d",&ck[i].w,&ck[i].l);
29         if(ck[i].w > ck[i].l) swap(ck[i].w,ck[i].l);
30     }
31
32     sort(ck,ck+N);
33
34     int m;
35     int answ,ansl;
36     ll ans = -INF;
37
38     for(int i=0;i<N;i++)
39     {
40         m = 0;
41         for(int j=0;j<N;j++)
42         {
43             if(ck[j].w >= ck[i].w)
44             {
45                 len[m++] = ck[j].l;
46             }
47         }
48         for(int j=0;j<m;j++)
49         {
50             ll res = (ll)ck[i].w*len[j]*(j+1);
51             if(res > ans)
52             {
53                 ans = res;
54                 answ = ck[i].w;
55                 ansl = len[j];
56             }
57         }
58     }
59     printf("%I64d\n%d %d\n",ans,answ,ansl);
60
61 }
时间: 2024-08-25 05:30:59

CodeForces 589B-Layer Cake-暴力模拟的相关文章

CodeForces 589B Layer Cake (暴力)

题意:给定 n 个矩形是a*b的,问你把每一块都分成一样的,然后全放一块,高度都是1,体积最大是多少. 析:这个题,当时并没有完全读懂题意,而且也不怎么会做,没想到就是一个暴力,先排序,先从大的开始选,如果大,那么数量少,如果小,数量就多, 用一个multiset来排序,这样时间复杂度会低一点,每一个都算一下比它的大矩阵的数量,然后算体积,不断更新,最大值. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #i

Codeforces 589B Layer Cake(两次排序)

题目地址:http://codeforces.com/problemset/problem/589/B 思路:设长<=宽,将各物体按长从小到大排序.从后向前枚举长,同时将宽加入并排序.则对于位置 j 的宽,有 num-j 物体宽大于它(由于长从小到大枚举,保证新加入物体的长不大于当前物体的长),则体积 a[i].r*b[j]*(num-j) 每次取最大即可. #include<cstdio> #include<cstring> #include<iostream>

CodeForce 589B Layer Cake

Layer Cake 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

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

hdu 5640 King&#39;s Cake(模拟)

Problem Description It is the king's birthday before the military parade . The ministers prepared a rectangle cake of size n×m(1≤n,m≤10000) . The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time, he will cut

hdu 5641 King&#39;s Phone(暴力模拟题)

Problem Description In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen. The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as

HDU 4831 Scenic Popularity 暴力模拟

Scenic Popularity Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 340    Accepted Submission(s): 110 Problem Description 临近节日,度度熊们最近计划到室外游玩公园,公园内部包括了很多的旅游景点区和休息区,由于旅游景点很热门,导致景点区和休息区都聚集了很多人.所以度度熊

Codeforces 475C Kamal-ol-molk&#39;s Painting 模拟

题目链接:点击打开链接 题意:给定n*m的矩阵 X代表有色 .代表无色 用一个x*y的矩阵形刷子去涂色. 刷子每次可以→或↓移动任意步. 若能够染出给定的矩阵,则输出最小的刷子的面积 若不能输出-1 思路: 先找到连续最小的x,y 因为至少一个边界和x或y相等,所以枚举(x,i) 和 (i,y)就可以了. #pragma comment(linker, "/STACK:102400000,102400000") #include <stdio.h> #include <

HDU 4858 项目管理(邻接表 暴力模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! 两个节点间可能有多条边,不过一条边的两端必然是不同的节点.每个节点都有一个能量值. 现在我们要编写一个项目管理软件,这个软件呢有两个操作:1.给某个项目的能量值加上一个特定值.2.询问跟一个项目相邻的项目的能量值之和.(如果有多条边就算多次,比如a和b有2条边,那么询问a的时候b的权值算2次). 解题报告:这个

Codeforces 57C Array dp暴力找规律

题目链接:点击打开链接 先是计算非递增的方案, 若非递增的方案数为x, 则非递减的方案数也是x 答案就是 2*x - n 只需求得x即可. 可以先写个n3的dp,然后发现规律是 C(n-1, 2*n-1) 然后套个逆元即可. #include<iostream> #include<cstdio> #include<vector> #include<string.h> using namespace std; #define ll long long #def