题目链接

大意就是给出一个序列, 然后让你从中找出一个严格递增的数列, 使得这一数列里的值加起来最大。

用线段树, 先将数列里的值离散,然后就是线段树单点更新, 区间查询最值。

具体看代码。

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
ll v[], b[], sum[*];
int id[];
void pushUp(int rt) {
sum[rt] = max(sum[rt<<], sum[rt<<|]);
}
void update(int p, ll val, int l, int r, int rt) {
if(l == r) {
sum[rt] = val;
return ;
}
int m = l+r>>;
if(p<=m)
update(p, val, lson);
else
update(p, val, rson);
pushUp(rt);
}
ll query(int L, int R, int l, int r, int rt) {
if(R<L)
return ;
if(L<=l&&R>=r) {
return sum[rt];
}
int m = l+r>>;
ll ret = ;
if(L<=m)
ret = query(L, R, lson);
if(R>m)
ret = max(ret, query(L, R, rson));
return ret;
}
int main()
{
int n, r, h;
cin>>n;
for(int i = ; i<n; i++) {
scanf("%d%d", &r, &h);
v[i] = b[i] = 1LL*r*r*h;
}
sort(b, b+n);
int num = unique(b, b+n)-b;
for(int i = ; i<n; i++) {
id[i] = lower_bound(b, b+num, v[i])-b+;
}
ll ans = ;
for(int i = ; i<n; i++) {
ll tmp = query(, id[i]-, , num, );
update(id[i], tmp+v[i], , num, );
ans = max(ans, tmp+v[i]);
}
printf("%.8f", ans*PI);
return ;
}

codeforces 629D. Babaei and Birthday Cake的更多相关文章

  1. Codeforces 629D Babaei and Birthday Cake(树状数组优化dp)

    题意: 线段树做法 分析: 因为每次都是在当前位置的前缀区间查询最大值,所以可以直接用树状数组优化.比线段树快了12ms~ 代码: #include<cstdio> #include< ...

  2. Codeforces 629D Babaei and Birthday Cake(线段树优化dp)

    题意: n个蛋糕编号从小到大编号,j号蛋糕可以放在i号上面,当且仅当j的体积严格大于i且i<j,问最终可得的最大蛋糕体积. 分析: 实质为求最长上升子序列问题,设dp[i]从头开始到第i位的最长 ...

  3. Codeforces 629D Babaei and Birthday Cakes DP+线段树

    题目:http://codeforces.com/contest/629/problem/D 题意:有n个蛋糕要叠起来,能叠起来的条件是蛋糕的下标比前面的大并且体积也比前面的大,问能叠成的最大体积 思 ...

  4. 629D - Babaei and Birthday Cake

    题意:给定n个圆柱体的半径和高,输入顺序即圆柱体的编号顺序.现在规定,只有编号和体积均大于另一个圆柱体,才能放到另一个圆柱体的体积上面.求能叠加的最大体积是多少. 酝酿了我三天,才理解.自己敲个代码, ...

  5. codeforces 629D D. Babaei and Birthday Cake (线段树+dp)

    D. Babaei and Birthday Cake time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake 线段树维护dp

    D. Babaei and Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/D Description As you ...

  7. 【20.19%】【codeforces 629D】Babaei and Birthday Cake

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. Codeforces Round #343 (Div. 2) D - Babaei and Birthday Cake 线段树+DP

    题意:做蛋糕,给出N个半径,和高的圆柱,要求后面的体积比前面大的可以堆在前一个的上面,求最大的体积和. 思路:首先离散化蛋糕体积,以蛋糕数量建树建树,每个节点维护最大值,也就是假如节点i放在最上层情况 ...

  9. codeforces 629D 树状数组+LIS

    题意:n个圆柱形蛋糕,给你半径 r 和高度 h,一个蛋糕只能放在一个体积比它小而且序号小于它的蛋糕上面,问你这样形成的上升序列中,体积和最大是多少 分析:根据他们的体积进行离散化,然后建树状数组,按照 ...

随机推荐

  1. Hash 表详解(哈希表)

    散列表(Hash table,也叫哈希表),是根据关键码值(Key value)而直接进行访问的数据结构.也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度.这个映射函数叫做散列 ...

  2. iso-开发基础知识-5-适配器

    个人学习总结仅供参考:欢迎拍砖 1.适配器:用于连接两种不同种类的对象. 2.分为2种:类适配,对象适配. 3.委托(Delegate)模式属于对象适配器: 4.何时使用适配器模式 书中的这幅图更好的 ...

  3. mongoose查询特定时间段文档的方法

    db.collection.find({ time:{ "$gte": new Date('2014-01-24'), "$lte":new Date('201 ...

  4. Android 中万能的 BaseAdapter(Spinner,ListView,GridView) 的使用!

    大家好!今天给大家讲解一下BaseAdapter(基础适配器)的用法,适配器的作用主要是用来给诸如(Spinner,ListView,GridView)来填充数据的.而(Spinner,ListVie ...

  5. ubuntu之iptables

    1.更新iptables并立即生效: a.保存当前设置:iptables-save > /etc/iptables.up.rules b.修改iptables规则: 例如: -I INPUT - ...

  6. Undefined symbols for architecture xxx

    解决方法: "Build Settings"->"Linking"->"Other Linker Flags" add the ...

  7. 浅谈Servlet(一)

    一.Servlet技术引言 1.什么是servlet a.Servlet(Server Applet),全称Java Servlet,未有中文译文.是用Java编写的服务器端程序.其主要功能在于交互式 ...

  8. USACO Section 5.3 Milk Measuring (IDDFS+dp)

    迭代加深搜索,从小到大枚举桶数的上限maxd:对每个maxd,枚举每个组合,判断是否能够倒出q:直到得到answer.判断的部分就用dp(完全背包). ------------------------ ...

  9. js常用的一些正则验证文本框

    只允许输入数字和-onKeyUp="value=value.replace(/[^-\d]/g,'')" onafterpaste="value=value.replac ...

  10. HDU3535-AreYouBusy

    描述: As having become a junior, xiaoA recognizes that there is not much time for her to AC problems, ...