【HDOJ】1823 Luck and Love
二维线段树。wa了几次,不存在输出-1,而不再是一位小数。
#include <cstdio>
#include <cstring> #define MAXN 105
#define MAXM 1005
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 double sons[MAXN<<][MAXM<<]; inline double mymax(double a, double b) {
return (a>b) ? a:b;
} inline void PushUP(int rt, int index) {
sons[index][rt] = mymax(sons[index][rt<<], sons[index][rt<<|]);
} void build_son(int l, int r, int rt, int index) {
sons[index][rt] = -;
if (l == r)
return ;
int mid = (l+r)>>;
build_son(lson, index);
build_son(rson, index);
} void build(int l, int r, int rt) {
build_son(, , , rt);
if (l == r)
return ;
int mid = (l+r)>>;
build(lson);
build(rson);
} void Update_son(int l, int r, int rt, int A, double L, int index) {
if (l == r) {
if (L > sons[index][rt])
sons[index][rt] = L;
return ;
}
int mid = (l+r)>>;
if (A <= mid)
Update_son(lson, A, L, index);
else
Update_son(rson, A, L, index);
PushUP(rt, index);
} void Update(int l, int r, int rt, int H, int A, double L) {
Update_son(, , , A, L, rt);
if (l == r)
return ;
int mid = (l+r)>>;
if (H <= mid)
Update(lson, H, A, L);
else
Update(rson, H, A, L);
} double query_son(int ll, int rr, int l, int r, int rt, int index) {
if (ll<=l && rr>=r)
return sons[index][rt]; int mid = (l+r)>>;
double max = -; if (ll <= mid)
max = mymax(max, query_son(ll, rr, lson, index));
if (rr > mid)
max = mymax(max, query_son(ll, rr, rson, index));
return max;
} double query(int ll, int rr, int l, int r, int rt, int A1, int A2) {
if (ll<=l && rr>=r)
return query_son(A1, A2, , , , rt); int mid = (l+r)>>;
double max = -; if (ll <= mid)
max = mymax(max, query(ll, rr, lson, A1, A2));
if (rr > mid)
max = mymax(max, query(ll, rr, rson, A1, A2));
return max;
} int main() {
int n;
int h1, h2, tmp;
double a, b, c;
char cmd[]; while (scanf("%d", &n)!=EOF && n) {
build(, , );
while (n--) {
scanf("%s", cmd);
if (cmd[] == 'I') {
scanf("%d %lf %lf", &h1, &a, &b);
Update(, , , h1, (int)(a*), b);
} else {
scanf("%d %d %lf %lf", &h1, &h2, &a, &b);
if (h1 > h2) {
tmp = h1;
h1 = h2;
h2 = tmp;
}
if (a > b) {
c = a;
a = b;
b = c;
}
b = query(h1, h2, , , , (int)(a*), (int)(b*));
if (b < )
printf("-1\n");
else
printf("%.1lf\n", b);
}
}
} return ;
}
【HDOJ】1823 Luck and Love的更多相关文章
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- 【HDOJ】【3530】Subsequence
DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...
- 【HDOJ】【3068】最长回文
Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...
- 【HDOJ】【1512】Monkey King
数据结构/可并堆 啊……换换脑子就看了看数据结构……看了一下左偏树和斜堆,鉴于左偏树不像斜堆可能退化就写了个左偏树. 左偏树介绍:http://www.cnblogs.com/crazyac/arti ...
随机推荐
- CSS背景颜色、背景图片、平铺、定位、固定
CSS背景颜色设置 background-color:red;如设置背景颜色为红色: 背景颜色设置支持3种写法: 颜色名 16进制 rgb CSS背景图片颜色设置 background-image:u ...
- WPF 格式化输出- IValueConverter接口的使用
以前在用ASP.NET 做B/S系统时,可以方便地在GRIDVIEW DATAList等数据控件中,使用自定义的代码逻辑,比如 使用 <%# GetBalance(custID) %> 这 ...
- ReactiveCocoa 中signal(operation) then与doNext的区别
贴源码: doNext:实现的主要源代码 return [[RACSignal createSignal:^(id<RACSubscriber> subscriber) {return [ ...
- 【转】JavaScript中的constructor与prototype
最初对js中 object.constructor 的认识: 在学习JS的面向对象过程中,一直对constructor与prototype感到很迷惑,看了一些博客与书籍,觉得自己弄明白了,现在记录如下 ...
- [功能帮助类] JsHelper--Javascript操作帮助类 (转载)
点击下载 JsHelper.rar 这个类是关于加密,解密的操作,文件的一些高级操作1.Javascript弹出信息,并跳转指定页面. 2.Javascript弹出信息,并返回历史页面3.Javasc ...
- .NET中的消息队列
下文参考:http://hi.baidu.com/21tian/blog/item/ce5464097ddf10cb3ac76335.html为何使用消息队列 您可能认为您能够通过一个简单的数据库表( ...
- oracle查询最占用资源的查询
从V$SQLAREA中查询最占用资源的查询 select b.username username,a.disk_reads reads,a.executions exec,a.disk_reads/d ...
- IOS-objectForKey与valueForKey在NSDictionary中的差异
从 NSDictionary 取值的时候有两个方法,objectForKey: 和 valueForKey:,这两个方法具体有什么不同呢? 先从 NSDictionary 文档中来看这两个方法的定义: ...
- Eclipse反编译工具Jad及插件
Eclipse反编译工具Jad及插件下载路径 http://download.csdn.net/detail/lijun7788/9689312 http://files.cnblogs.com/fi ...
- 查看当前linux系统位数
linux系统也有位数之分,所以在linux上安装一些软件,比如jdk之类的就需要注意下版本. 查看linux系统位数最简单的命令(这里以redhat为例,不同版本linux命令也许不同) 命令1:g ...