D. Babaei and Birthday Cake---cf629D(LIS线段树优化)
题目链接:http://codeforces.com/problemset/problem/629/D
题意就是现有n个蛋糕,蛋糕的形状是圆柱体,每个蛋糕的体积就是圆柱体的体积,每个蛋糕的编号是1---n,可以把蛋糕 i 放到蛋糕 j 上面,前提是 j<i 并且 Vj<Vi;最后求最大的体积是多少;
实质就是求上升子序列的最大和,但是由于n的范围是10w所以不能用n^2的复杂度,所以可以用线段树进行优化,时间复杂度变为nlogn;
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- #include <stack>
- #include <map>
- #include <vector>
- using namespace std;
- typedef long long LL;
- #define PI 4*atan(1.0)
- #define N 302000
- #define met(a, b) memset(a, b, sizeof(a))
- #define Lson r<<1
- #define Rson r<<1|1
- double v[N], b[N];
- struct node
- {
- int L, R;
- double Max;///表示这个区间内的最大值,
- int Mid(){ return (L+R)/; }
- }a[N*];
- void Build(int r, int L, int R)
- {
- a[r].L = L, a[r].R = R;a[r].Max = ;
- if(L == R)return;
- Build(Lson, L, a[r].Mid());
- Build(Rson, a[r].Mid()+, R);
- }
- double Query(int r, int L, int R)
- {
- if(L > R) return ;
- if(a[r].L == L && a[r].R == R)
- return a[r].Max;
- if(R <= a[r].Mid())
- return Query(Lson, L, R);
- else if(L > a[r].Mid())
- return Query(Rson, L, R);
- else
- {
- double ans1 = Query(Lson, L, a[r].Mid());
- double ans2 = Query(Rson, a[r].Mid()+, R);
- return max(ans1, ans2);
- }
- }
- void Update(int r, int pos, double num)
- {
- if(a[r].L == a[r].R && a[r].L == pos)
- {
- a[r].Max = num;
- return ;
- }
- if(pos <= a[r].Mid())
- Update(Lson, pos, num);
- else
- Update(Rson, pos, num);
- a[r].Max = max(a[Lson].Max, a[Rson].Max);
- }
- int main()
- {
- int n;
- LL r, h;
- while(scanf("%d", &n)!=EOF)
- {
- for(int i=; i<=n; i++)
- {
- scanf("%I64d %I64d", &r, &h);
- v[i] = b[i] = PI*h*r*r;
- }
- sort(b, b+n);
- int len = unique(b, b+n) - b;
- Build(, , len);
- double ans = ;
- for(int i=; i<=n; i++)
- {
- int pos = lower_bound(b, b+len, v[i]) - b;///每次找到当前这个数能放的位置;
- double res = Query(, , pos-) + v[i];///找到这个位置之前的最大值
- Update(, pos, res);///找到之后把这个值加到那个位置上
- ans = max(ans, res);
- }
- printf("%.12f\n", ans);
- }
- return ;
- }
D. Babaei and Birthday Cake---cf629D(LIS线段树优化)的更多相关文章
- SGU 521 North-East ( 二维LIS 线段树优化 )
521. "North-East" Time limit per test: 0.5 second(s)Memory limit: 262144 kilobytes input: ...
- D. Babaei and Birthday Cake---cf629D(最长上升子序列和+线段树优化)
http://codeforces.com/problemset/problem/629/D 题目大意: 我第一反应就是求最长上升子序列和 但是数值太大了 不能直接dp求 可以用线段树优化一下 ...
- UVA-1322 Minimizing Maximizer (DP+线段树优化)
题目大意:给一个长度为n的区间,m条线段序列,找出这个序列的一个最短子序列,使得区间完全被覆盖. 题目分析:这道题不难想,定义状态dp(i)表示用前 i 条线段覆盖区间1~第 i 线段的右端点需要的最 ...
- Codeforces Round #426 (Div. 2) D 线段树优化dp
D. The Bakery time limit per test 2.5 seconds memory limit per test 256 megabytes input standard inp ...
- CodeForces 834D The Bakery(线段树优化DP)
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredient ...
- [USACO2005][POJ3171]Cleaning Shifts(DP+线段树优化)
题目:http://poj.org/problem?id=3171 题意:给你n个区间[a,b],每个区间都有一个费用c,要你用最小的费用覆盖区间[M,E] 分析:经典的区间覆盖问题,百度可以搜到这个 ...
- Weak Pair---hud5877大连网选(线段树优化+dfs)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5877 题意:给你一颗树,有n个节点,每个节点都有一个权值v[i]:现在求有多少对(u,v ...
- CodeForces 558E(计数排序+线段树优化)
题意:一个长度为n的字符串(只包含26个小字母)有q次操作 对于每次操作 给一个区间 和k k为1把该区间的字符不降序排序 k为0把该区间的字符不升序排序 求q次操作后所得字符串 思路: 该题数据规模 ...
- HDU4719-Oh My Holy FFF(DP线段树优化)
Oh My Holy FFF Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) T ...
随机推荐
- vnc 多用户登录
1, 创建新用户: $ useradd tom $ passwd tom 2, 登录到tom账户,创建vnc实例: $ su tom$ vncserver 这时可以看看~/.vnc/目录下,有一些如 ...
- ms-SQL 递归调用
----递归函数-------------------------------------------------------------------------- create function d ...
- 分配All AD User到SharePoint Group中
使用名称为“NT AUTHORITY\Authenticated Users”
- visual studio 2017使用NHibernate4.0连接oracle11g数据库
之前一直是公司用NHibernate2.1来做项目,连接oracle 10g的数据库,配置NHibernate的东西都是以前的同事做好了的,也怪自己太懒了,没尝试过配置这个东西,虽然一直在使用NHib ...
- Spring------Spring boot data jpa的使用方法
1.DoMain.java import org.springframework.boot.SpringApplication; import org.springframework.boot.aut ...
- Python3 urllib 库
urllib 简介 urllib 基础模块 使用 urllib 发送请求 使用 urllib 构造请求对象 关于 Handler 与 opener 使用 urllib 进行身份验证 使用 urllib ...
- stm32入门(从51过渡到32)
单片机对于我来说,就是一个超级大机器,上面有一排一排数不尽的开关,我需要做的,就是根据我的设计,拿着一张超级大的表(Datasheet),把需要的开关(reg)都开关(config)到对应功能的位置( ...
- Effective C++ —— 设计与声明(四)
条款18 : 让接口容易被正确使用,不易被误用 欲开发一个“容易被正确使用,不容易被误用”的接口,首先必须考虑客户可能做出什么样的错误操作. 1. 明智而审慎地导入新类型对预防“接口被误用”有神奇疗 ...
- On iPad, UIImagePickerController must be presented via UIPopoverController
本文转载至:http://blog.csdn.net/k12104/article/details/8537695 On iPad, UIImagePickerController must be p ...
- 使用类/结构体时关于ZeroMomery用法错误
今天同事在写了如下结构体: typedef struct _tagInfo { std::list<int> lst; std::vector<int> nVec; } INF ...