Codeforces 629D Babaei and Birthday Cake
来源:互联网 发布:软件开发报告 编辑:程序博客网 时间:2024/04/29 08:29
http://codeforces.com/problemset/problem/629/D
题意是说蛋糕i只能放在最底下或是放在一个编号比i小、体积也比i小的蛋糕上,求叠在一起的蛋糕体积和的最大值。类似于LIS。直接用dp肯定会超时,这里用线段树维护。
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <vector>#include <stack>#include <queue>#define fi first#define se second#define lson l, m, rt<<1#define rson m+1, r, rt<<1|1using namespace std;typedef long long LL;typedef pair<int, int> pii;//headconst double PI = acos(-1.0);const int maxn = 100005;LL t[maxn<<2];LL dp[maxn];LL v[maxn];LL vs[maxn];void pushup(int rt){ t[rt] = max(t[rt<<1], t[rt<<1|1]);}void build(int l, int r, int rt){ rt[t] = 0; int m = (l+r)>>1; if(l!=r) { build(lson); build(rson); }}LL query(int L, int R, int l, int r, int rt){ if(L<=l && r<=R)return t[rt]; int m = (l+r)>>1; LL ret = -1; if(L<=m) ret = max(ret, query(L, R, lson)); if(R>m) ret = max(ret, query(L, R, rson)); return ret;}void update(int l, int r, int rt, int pos, LL tgt){ if(l==r) { t[rt] = max(tgt, t[rt]); return; } int m = (l+r)>>1; if(pos<=m) update(lson, pos, tgt); else update(rson, pos, tgt); pushup(rt);}int main(){ int n; scanf("%d",&n); for(int i=1; i<=n; i++) { LL a,b; scanf("%I64d%I64d",&a,&b); v[i] = vs[i] = a*a*b; } build(1, n, 1); sort(vs+1, vs+n+1); LL ans = 0; for(int i=1; i<=n; i++) { int pos = lower_bound(vs+1, vs+n+1, v[i]) - vs; if(pos == 1) dp[i] = v[i]; else dp[i] = query(1, pos-1, 1, n, 1) + v[i]; update(1, n, 1, pos, dp[i]); ans = max(ans, dp[i]); } printf("%.9f\n", 1.0*PI*ans); return 0;}
0 0
- CODEFORCES 629 D Babaei and Birthday Cake
- CodeForces 629D Babaei and Birthday Cake
- Codeforces 629D Babaei and Birthday Cake
- codeforces 629 D. Babaei and Birthday Cake dp + 线段树
- Codeforces 629D Babaei and Birthday Cake(DP)
- Codeforces 629D - Babaei and Birthday Cake 线段树
- 【20.19%】【codeforces 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 Round #343 (Div. 2) D. Babaei and Birthday Cake
- Codeforces Round #343 (Div. 2) 629D. Babaei and Birthday Cake 线段树
- codeforces 629D-Babaei and Birthday Cake(dp && 线段树或树状数组离散优化)
- Codeforces 629D Babaei and Birthday Cake 【线段树优化dp】
- Codeforces 629D Babaei and Birthday Cake(线段树优化dp)
- Codeforces 629D Babaei and Birthday Cake(树状数组优化dp)
- CodeForces 629D Babaei and Birthday Cake(线段树维护DP)
- CodeForces 629D Babaei and Birthday Cake(树状数组+离散化)
- Codeforces 629D Babaei and Birthday Cake LIS+线段树优化
- spring 配置注解
- itop4412 LCD设备驱动详解(四)之PROBE再深入
- 两种方法解决ScrollView嵌套ListView出现ListView显示不全的问题
- 文本
- BZOJ 1833: [ZJOI2010]count 数字计数(在[a,b]中的所有整数中,每个数码(digit)各出现了多少次)
- Codeforces 629D Babaei and Birthday Cake
- 有关JDBC中preparedStatement的用法
- 开槽地平面的串扰分析
- BroadcastReceiver
- null和undefined
- live555—VS2010/VS2013 下live555编译、使用及测试
- Linux c==三种校验方法(10)
- 更博客 更博客 更博客
- 欧拉回路