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(最长上升子序列)有一点像

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

代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 1e5+6;
  4. typedef double SgTreeDataType;
  5. struct treenode
  6. {
  7. int L , R ;
  8. double sum;
  9. int num;
  10. void updata(SgTreeDataType v)
  11. {
  12. sum += v;
  13. }
  14. };
  15. treenode tree[500000];
  16. inline void push_down(int o)
  17. {
  18. }
  19. inline void push_up(int o)
  20. {
  21. tree[o].sum = max(tree[2*o].sum , tree[2*o+1].sum);
  22. if(tree[2*o].sum>tree[2*o+1].sum)
  23. tree[o].num=tree[2*o].num;
  24. else
  25. tree[o].num=tree[2*o+1].num;
  26. }
  27. inline void build_tree(int L , int R , int o)
  28. {
  29. tree[o].L = L , tree[o].R = R,tree[o].sum = 0;
  30. tree[o].num = L;
  31. if (R > L)
  32. {
  33. int mid = (L+R) >> 1;
  34. build_tree(L,mid,o*2);
  35. build_tree(mid+1,R,o*2+1);
  36. }
  37. }
  38. inline void updata2(int QL,int QR,SgTreeDataType v,int o)
  39. {
  40. int L = tree[o].L , R = tree[o].R;
  41. if (QL <= L && R <= QR)
  42. {
  43. tree[o].sum=max(tree[o].sum,v);
  44. }
  45. else
  46. {
  47. push_down(o);
  48. int mid = (L+R)>>1;
  49. if (QL <= mid) updata2(QL,QR,v,o*2);
  50. if (QR > mid) updata2(QL,QR,v,o*2+1);
  51. push_up(o);
  52. }
  53. }
  54. inline SgTreeDataType query(int QL,int QR,int o)
  55. {
  56. if(QR<QL)return 0;
  57. int L = tree[o].L , R = tree[o].R;
  58. if (QL <= L && R <= QR) return tree[o].sum;
  59. else
  60. {
  61. push_down(o);
  62. int mid = (L+R)>>1;
  63. SgTreeDataType res = 0;
  64. if (QL <= mid) res = max(query(QL,QR,2*o),res);
  65. if (QR > mid) res = max(query(QL,QR,2*o+1),res);
  66. push_up(o);
  67. return res;
  68. }
  69. }
  70. double h[maxn],r[maxn],v[maxn];
  71. const double pi = acos(-1.0);
  72. vector<double>V;
  73. map<double,int> H;
  74. int main()
  75. {
  76. int n;
  77. scanf("%d",&n);
  78. for(int i=1;i<=n;i++)
  79. {
  80. scanf("%lf%lf",&r[i],&h[i]),v[i]=pi*r[i]*r[i]*h[i];
  81. V.push_back(v[i]);
  82. }
  83. sort(V.begin(),V.end());
  84. V.erase(unique(V.begin(),V.end()),V.end());
  85. for(int i=0;i<V.size();i++)
  86. H[V[i]]=i+1;
  87. build_tree(1,n,1);
  88. for(int i=1;i<=n;i++)
  89. {
  90. double p = v[i]+query(1,H[v[i]]-1,1);
  91. updata2(H[v[i]],H[v[i]],p,1);
  92. }
  93. printf("%.12f\n",tree[1].sum);
  94. return 0;
  95. }

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. 多表数据转化器MTDC

    需求 根据配置文件的映射规则,将一种模型和数据映射成另外一种模型和数据.如图: 其中,a1,b1,c1,d1为表主键,关系:A.a1=B.b1=C.c2=D.d1 解决思路 解析模型配置文件,将每个转 ...

  2. Python3 hashlib模块和hmac 模块(加密)

    hashlib 是一个提供了一些流行的hash算法的 Python 标准库.其中所包括的算法有 md5, sha1, sha224, sha256, sha384, sha512等常用算法 MD5加密 ...

  3. HDU 5627 Clarke and MST &意义下最大生成树 贪心

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5627 题意:Bestcoder的一道题,让你求&意义下的最大生成树. 解法: 贪心,我们从高位 ...

  4. C基础 大文件读取通过标准库

    引言 - 问题的构建 C大部分读取文件的时候采用fgetc, 最近在使用过程中发现性能不是很理想.都懂得fgetc每次只能读取一个字符, IO操作太频繁. 所以性能低. 本文希望通过标准库函数frea ...

  5. python按比例随机切分数据

    在机器学习或者深度学习中,我们常常碰到一个问题是数据集的切分.比如在一个比赛中,举办方给我们的只是一个带标注的训练集和不带标注的测试集.其中训练集是用于训练,而测试集用于已训练模型上跑出一个结果,然后 ...

  6. vue知识点(1)

    处理用户输入 v-on指令添加一个事件监听器 div id="app-5"> <p>{{ message }}</p> <button v-on ...

  7. 微信小程序滚动条返回顶部

    scroll-view(可滚动视图区域): 使用竖向滚动时,需要给<scroll-view/>一个固定高度,通过 WXSS 设置 height,将scroll-y属性设置为true,将en ...

  8. div左右自适应高度一致

    <div style="width:300px;"> <div id="Left" style="float:left;" ...

  9. 关于ueditor在Java中文件上传问题,404问题

    问题困扰了两天,部署要求导入到webcontent下,我导入到了整个项目目录下,自己粗心犯错,导致页面访问不到404. 解决了上面的问题,试着进行文件上传,却一直找不到图片: 调出浏览器控制台: 刚开 ...

  10. rabbitmq源码安装及配置文件管理

    rabbitmq 源码安装 官网地址:rabbitmq http://www.rabbitmq.com/releases/rabbitmq-server/ 官网地址:erlang http://erl ...