D. Babaei and Birthday Cake

题目连接:

http://www.codeforces.com/contest/629/problem/D

Description

As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.

Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.

However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.

Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.

Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.

Output

Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

Sample Input

2

100 30

40 10

Sample Output

942477.796077000

Hint

题意

有n个蛋糕,然后第i个蛋糕只能放在地上或者放在体积和编号都比他小的上面

然后问你体积最多能堆多大?

题解:

用线段树维护DP

显然这个东西和lis(最长上升子序列)有一点像

我们首先把每个东西的体积都离散化一下,然后我们选取比他小的最大值,然后进行更新就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+6;
typedef double SgTreeDataType;
struct treenode
{
int L , R ;
double sum;
int num;
void updata(SgTreeDataType v)
{
sum += v;
}
}; treenode tree[500000]; inline void push_down(int o)
{ } inline void push_up(int o)
{
tree[o].sum = max(tree[2*o].sum , tree[2*o+1].sum);
if(tree[2*o].sum>tree[2*o+1].sum)
tree[o].num=tree[2*o].num;
else
tree[o].num=tree[2*o+1].num;
} inline void build_tree(int L , int R , int o)
{
tree[o].L = L , tree[o].R = R,tree[o].sum = 0;
tree[o].num = L;
if (R > L)
{
int mid = (L+R) >> 1;
build_tree(L,mid,o*2);
build_tree(mid+1,R,o*2+1);
}
}
inline void updata2(int QL,int QR,SgTreeDataType v,int o)
{
int L = tree[o].L , R = tree[o].R;
if (QL <= L && R <= QR)
{
tree[o].sum=max(tree[o].sum,v);
}
else
{
push_down(o);
int mid = (L+R)>>1;
if (QL <= mid) updata2(QL,QR,v,o*2);
if (QR > mid) updata2(QL,QR,v,o*2+1);
push_up(o);
}
}
inline SgTreeDataType query(int QL,int QR,int o)
{
if(QR<QL)return 0;
int L = tree[o].L , R = tree[o].R;
if (QL <= L && R <= QR) return tree[o].sum;
else
{
push_down(o);
int mid = (L+R)>>1;
SgTreeDataType res = 0;
if (QL <= mid) res = max(query(QL,QR,2*o),res);
if (QR > mid) res = max(query(QL,QR,2*o+1),res);
push_up(o);
return res;
}
} double h[maxn],r[maxn],v[maxn];
const double pi = acos(-1.0);
vector<double>V;
map<double,int> H;
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&r[i],&h[i]),v[i]=pi*r[i]*r[i]*h[i];
V.push_back(v[i]);
}
sort(V.begin(),V.end());
V.erase(unique(V.begin(),V.end()),V.end());
for(int i=0;i<V.size();i++)
H[V[i]]=i+1;
build_tree(1,n,1);
for(int i=1;i<=n;i++)
{
double p = v[i]+query(1,H[v[i]]-1,1);
updata2(H[v[i]],H[v[i]],p,1);
}
printf("%.12f\n",tree[1].sum);
return 0;
}

Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake 线段树维护dp的更多相关文章

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

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

  2. Codeforces Round #321 (Div. 2) E Kefa and Watch (线段树维护Hash)

    E. Kefa and Watch time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)

    题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...

  4. Codeforces Round #332 (Div. 2) C. Day at the Beach 线段树

    C. Day at the Beach Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/p ...

  5. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸

    D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  6. Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)

    题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...

  7. Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)

    题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x, ...

  8. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game 线段树贪心

    B. "Or" Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/578 ...

  9. Codeforces Round #489 (Div. 2) E. Nastya and King-Shamans(线段树)

    题意 给出一个长度为 \(n\) 的序列 \(\{a_i\}\) , 现在会进行 \(m\) 次操作 , 每次操作会修改某个 \(a_i\) 的值 , 在每次操作完后你需要判断是否存在一个位置 \(i ...

随机推荐

  1. Django rest framework 版本控制(源码分析)

    基于上述分析 #2.处理版本信息 处理认证信息 处理权限信息 对用户的访问频率进行限制 self.initial(request, *args, **kwargs) #2.1处理版本信息 #versi ...

  2. C++之容器(关联容器)

    关联容器和顺序容器的本质区别:关联容器是通过键存取和读取元素.顺序容器通过元素在容器中的位置顺序存储和访问元素.因此,关联容器不提供front.push_front.pop_front.back.pu ...

  3. 【bzoj3682】Phorni

    后缀平衡树裸题. 后缀平衡树呢,实际上是一个很naive的东西.就是用平衡树维护后缀数组. 这样的话就可以支持在最前端插入一个字符(相当于插入新的后缀) 每次比较节点的tag是O(1)的,所以可以快速 ...

  4. 【学习笔记】动态树Link-Cut-Tree

    这是两个月前写的,看能不能搬运过来…… 动态树是一类维护森林连通性的问题(已纠正,感谢ZQC巨佬),目前最(wo)常(zhi)见(hui)的动态树就是LCT(Link-Cut-Tree),然而LCT似 ...

  5. [hadoop][基本原理]zookeeper场景使用

    代码:https://github.com/xufeng79x/ZkClientTest 1. 简介 zookeeper的特性决定他适用到某些场景非常合适,比如典型的应用场景: 1.集群管理(Grou ...

  6. PIL处理图片信息

    最近遇到了图片处理的一些问题,python提供了一些库可以很方便地帮助我们解决这些问题,在这里把我这几天的学习总结一下. 一.提取图片的RGB值 1.非代码:如果只是为了提取某张图片或者某个像素点的R ...

  7. mysql设置服务器编码

    今天写java程序的时候出现了插入mysql数据中文乱码问题,确定数据库和表的编码都已指定utf-8.百度后得知mysql安装后需设置服务器编码,以下是解决方法(ubuntu; mysql 5.6.2 ...

  8. linux命令(32):free命令

    1.显示内存使用情况:free  free –g  free –m 2.以总和的形式显示内存的使用信息: free -t 3.周期性的查询内存使用信息:free -s 10

  9. Django Rest Framework用户访问频率限制

    一. REST framework的请求生命周期 基于rest-framework的请求处理,与常规的url配置不同,通常一个django的url请求对应一个视图函数,在使用rest-framewor ...

  10. 常用SQL时间格式SQLServer中文版的默认的日期字段datetime格式是yyyy-mm-d

    常用SQL时间格式 SQL Server中文版的默认的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm 例如: select getdate() -- ::08.177 ...