Codeforces589B Layer Cake
来源:互联网 发布:linux视频聊天软件 编辑:程序博客网 时间:2024/06/08 02:33
题目见此链接Codeforces589B Layer Cake
题目大意:
主人公要堆砌一个多层的蛋糕,而每一层的蛋糕都将是一个正方形,而每层的正方形蛋糕都是由同一个型号的小蛋糕拼成的(每层的正方形也都是一个规格的)。比如:小蛋糕的规格是width*length(蛋糕的高度都是单位1),那么大正方形的规格便是width*length,由此也可以知道每层大蛋糕需要的小蛋糕数量是num = width*length。同时大蛋糕也可以切成小蛋糕,比如12*5规格可以切成6*4规格,以满足种类扩充。
*具体思路:
1)先规定输入的不同型号蛋糕的长和宽,再将蛋糕放在数轴上(蛋糕的宽放置在数轴上)
2)对所有蛋糕排序:以蛋糕的宽度为标准,从大到小排列
3)从1到n个蛋糕开始遍历,每次选i-th个蛋糕的宽作为之后统一标准的蛋糕的宽度标准
4)对于其余蛋糕的选取,只需要考虑第i 个之前的蛋糕类型就可以,也就是宽度比标准型大的蛋糕
5)每次对前i-1个蛋糕进行以高度递减的重排,逐次进行抽取
以下是代码
#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int maxn = 4000 + 2;struct Point{int first, second;};Point cake_type[maxn];bool camp_1(Point& lhs, Point& rhs) {return lhs.first > rhs.first;}bool camp_2(Point& lhs, Point& rhs) {return lhs.second > rhs.second;}int main(int argc, const char * argv[]) { // insert code here... int n; while (cin >> n) { for (int i = 1; i <= n; i++) { cin >> cake_type[i].first >> cake_type[i].second; if (cake_type[i].first > cake_type[i].second) swap(cake_type[i].first, cake_type[i].second); } sort(cake_type + 1, cake_type + n + 1, camp_1); long long int max = (long long)cake_type[1].first*(long long)cake_type[1].second;//初始化max long long int wide_a = cake_type[1].first, high_b = cake_type[1].second;//初始化标准长宽 for (int i = 1; i <= n; i++) { sort(cake_type + 1, cake_type + i, camp_2);//前段重排 int j = 1; while (j < i) { long long int temp_b = min(cake_type[i].second, cake_type[j].second); long long int temp = temp_b*(j + 1)*(long long)cake_type[i].first; if (temp > max) { max = temp; wide_a = cake_type[i].first; high_b = cake_type[j].second; } j++; } } cout << max << "\n" << wide_a << " " << high_b << endl; } return 0;}
AC 800ms/0kb
0 0
- Codeforces589B Layer Cake
- codeforces589B Layer Cake (动态规划)
- cf589B Layer Cake 排序
- CodeForces 589B Layer Cake
- CodeForces 589B Layer Cake
- CodeForces 589B Layer Cake(枚举)
- Codeforces 589B Layer Cake(两次排序)
- cake
- Cake
- Cake
- Cake
- Cake
- Cake
- Cake
- Cake
- cake
- Cake
- Cake
- java中参数传递
- Apache Commons工具集简介
- C语言学习-通过柴田望洋的《明解C语言》(2)
- hibernate 关联关系
- 【NOIP】10.27集训总结
- Codeforces589B Layer Cake
- 工厂设计模式
- 重要的JAVA-API String类
- c++ int 转char * 函数 _itoa_s
- 为什么在能够在线访问 S7-1500 CPU 的情况下却不能下载项目?
- get与post提交方式的区别
- Gabor小波变换滤波器原理与创建
- Android学习笔记之AndroidManifest.xml文件解析
- 在ionic中使用$q同步读取sqlite3记录