Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake (复杂的DP)
来源:互联网 发布:淘宝双十一报名入口 编辑:程序博客网 时间:2024/05/17 06:22
题目链接:http://codeforces.com/problemset/problem/629/D
题意:给你n个圆柱体的底面半径r和高h,求最大能放在一起的总体积,条件是i放到j上 Vi >= Vj 并且i > j
解析:显然是一个DP题,但数据比较大,需要优化,这里用到了map优化,就是mp[i]一直是最优的,每输入一个圆柱体i,就要二分mp里面的>=该体积的值j,存下当前值与二分到的j的上一个相加,cnt = (--R)->second + v; 然后遍历把小于cnt的值都给删了,再把mp[v] = cnt;存进去,这样就保证了所有体积都最优
借鉴 hpu 纯真学姐 博客 :http://blog.csdn.net/zwj1452267376/article/details/50720228
代码:
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<vector>#include<queue>#include<map>#include<cmath>#include<string>#define N 1009using namespace std;const int INF = 0x3f3f3f3f;typedef __int64 LL;map<LL, LL> mp;int main(){ int n; LL r, h; scanf("%d", &n); mp[0] = 0; for(int i = 1; i <= n; i++) { scanf("%I64d %I64d", &r, &h); LL v = r * r * h; map<LL, LL>::iterator L = mp.lower_bound(v); map<LL, LL>::iterator R = L; LL cnt = (--R)->second + v; R = L; for(; R != mp.end() && R->second <= cnt; R++) ; mp.erase(L, R); //删除[l,r)之间元素 mp[v] = cnt; } printf("%.9f\n", (--mp.end())->second * acos(-1.0)); return 0;}
0 0
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake (复杂的DP)
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake(dp、BIT)
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake(线段树+dp)
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake(dp + BIT)
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake(线段树+离散化优化DP)
- Codeforces Round #343 (Div. 2) 629D. Babaei and Birthday Cake 线段树
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake(离散化+线段树)
- Codeforces Round #343 (Div. 2)D - Babaei and Birthday Cake 线段树
- codeforces #343 div2 D. Babaei and Birthday Cake(DP+离散化+线段树优化)
- codeforces 629 D. Babaei and Birthday Cake dp + 线段树
- Codeforces 629D Babaei and Birthday Cake(DP)
- CODEFORCES 629 D Babaei and Birthday Cake
- CodeForces 629D Babaei and Birthday Cake
- Codeforces 629D Babaei and Birthday Cake
- Codeforces 629D Babaei and Birthday Cake(线段树优化dp)
- 九度OJ题目1173:查找
- 二维数组中查找数据(该数组每行从左至右递增,每列从上至下递增)
- 为Recycler添加下拉刷新,上拉加载更多功能(简单实现)
- unity Ngui
- PostgreSQL常用语句
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake (复杂的DP)
- 关于listView ui更新的问题
- mongodb[三] 文档操作:插入、更新、删除
- POJ-3685-二分
- 了解LoRa
- 无人机常用术语及缩写
- 输入字母来判断星期几的问题
- 国有资产管理处组织召开新版固定资产管理系统操作培训会
- Shell对IP合法性检查