time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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 .

Examples

input

2

100 30

40 10

output

942477.796077000

input

4

1 1

9 7

1 4

10 7

output

3983.539484752

Note

In first sample, the optimal way is to choose the cake number 1.

In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4.

【题解】



DP

设f[i]表示以i号蛋糕作为最上面一层能获取到的最大体积;

f[i] = max(f[j])+v[i];(1<=j<=i-1);

其中j要满足v[j]小于v[i]

(不能等于!)

这样做肯定是O(N^2),而N最大10W。。

考虑到我们需要1..i-1里面小于v[i]且f最大的f值;

则我们考虑用线段树来维护;

这里需要先把数据离散化一下(离散化的标准以r^2*h就好,pi作为一个常数不用乘进去);

然后用lower_bound什么的获取每个数据新的key值;

key值小的对应的数据就小;

则我们顺序处理保证了i小于j;

然后在1..key[i]-1里面找f最大的值;

这里另外一层含义就是说把体积当下标来使用;

f[体积]表示以这个体积作为最上面一层的蛋糕的最大体积;

这里线段树就维护了f[1..当前体积-1]里的最大值,并快速检索;

当然在计算体积的时候要把pi乘进去;

当然你也可以选择加完之后输出答案的时候再乘;

whatever.

#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson L,m,rt<<1
#define rson m+1,R,rt<<1|1
#define LL long long using namespace std; const int MAXN = 2e5;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0); int n,key[MAXN];
LL v[MAXN],r[MAXN],h[MAXN];
double maxsum[MAXN<<2];
vector <LL> a; void input_LL(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void input_int(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void build(int L,int R,int rt)
{
maxsum[rt] = 0;
int m = (L+R)>>1;
if (L==R)
return;
build(lson);
build(rson);
} double query(int l,int r,int L,int R,int rt)
{
if (l>r)
return 0;
if (l <= L && R <= r)
return maxsum[rt];
int m = (L+R)>>1;
double res = 0;
if (l <= m)
res = max(res,query(l,r,lson));
if (m < r)
res = max(res,query(l,r,rson));
return res;
} void up_data(int pos,double ke,int L,int R,int rt)
{
if (L==R)
{
maxsum[rt] = max(maxsum[rt],ke);
return;
}
int m = (L+R)>>1;
if (pos<=m)
up_data(pos,ke,lson);
else
up_data(pos,ke,rson);
maxsum[rt] = max(maxsum[rt<<1],maxsum[rt<<1|1]);
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
input_int(n);
for (int i = 1;i <= n;i++)
{
scanf("%d%d",&r[i],&h[i]);
v[i] =r[i]*r[i]*h[i];
a.push_back(v[i]);
}
sort(a.begin(),a.end());
for (int i = 1;i <= n;i++)
key[i] = lower_bound(a.begin(),a.end(),v[i])-a.begin()+1;
build(1,n,1);
for (int i = 1;i <= n;i++)
{
double vo = pi*r[i]*r[i]*h[i];
vo += query(1,key[i]-1,1,n,1);
up_data(key[i],vo,1,n,1);
}
printf("%.10lf\n",query(1,n,1,n,1));
return 0;
}

【20.19%】【codeforces 629D】Babaei and Birthday Cake的更多相关文章

  1. 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 ...

  2. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  3. 【19.77%】【codeforces 570D】Tree Requests

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

  4. 【20.23%】【codeforces 740A】Alyona and copybooks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【19.46%】【codeforces 551B】ZgukistringZ

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

  6. 【44.19%】【codeforces 608D】Zuma

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

  7. 【20.51%】【codeforces 610D】Vika and Segments

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

  8. 【77.78%】【codeforces 625C】K-special Tables

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. 【codeforces 515C】Drazil and Factorial

    [题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的 ...

随机推荐

  1. Hamming correct

    从数的最左边开始,并标记为1 将2的平方的位置留出来,做为校验位例如,8位2进制数10011010===>_ _ 1 _ 0 0 1 _ 1 0 1 0 位置1用来校验最右边的位位1的位置1 3 ...

  2. Java基础学习总结(28)——Java对各种排序算法的实现

    这里总结下各种排序算法的java实现 冒泡排序 public class BubbleSort { publicstaticint[] bubbleSort(int[] array) { if(arr ...

  3. 这一篇sigmoid和softmax的比较,讲的不错

    文章: http://blog.csdn.net/u014422406/article/details/52805924 sigmoid函数(也叫逻辑斯谛函数):  引用wiki百科的定义: A lo ...

  4. android 蓝牙各种UUID

    ServiceDiscoveryServerServiceClassID_UUID = '{00001000-0000-1000-8000-00805F9B34FB}' BrowseGroupDesc ...

  5. IIS FTP匿名登录不成功

    FTP网站没有开启匿名登录的权限,对你没有看错.可能你的虚拟目录已经设置了如下所示的内容:    但是,单击上右图时,在其功能视图中的FTP身份验证中,可能并未启用"匿名身份验证",如下右图所示.启动 ...

  6. Launcher Activity在开机时重新启动两次解决的方法

    今天在看log的时候发现,Launcher activity会被onDestroy掉一次.然后再重新启动. 可能原因推測: 1.横竖屏切换 2.MCC MNC等Configuration改变引起的 M ...

  7. testng并发测试与测试并发

    一.testng并发测试 通过xml文件中suit结点的parallel属性指定,如 <suite name="bundle-module-testabc" parallel ...

  8. Linux动态链接库的创建与使用

    Linux动态链接库的创建与使用1. 介绍     使用GNU的工具我们如何在Linux下创建自己的程序函数库?一个“程序函数库”简单的说就是一个文件包含了一些编译好的代码和数据,这些编译好的代码和数 ...

  9. CleanCode代码整洁之道培训总结(2015-03-14)

    为期四天的CleanCode培训时间非常短.非常难准确掌握一些知识.但让我对代码有了一个又一次的认识和启示:之前也有看过设计模式.重构之类的书,看完之后也有一些感触,过后在写代码中还是不能应用进来,事 ...

  10. 读Effective Objective-C [提高OC代码质量总结笔记第一篇:熟悉OC]

    一.OC特性 OC 为 C 语言添加了面向对象特性,是其超集; OC 使用动态绑定的消息结构,也就是,在运行时才会检查对象类型; 接收一条消息后,究竟应执行何种代码,由运行期环境来决定,而非 编译器; ...