【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 ...
随机推荐
- iOS 关于开发者证书:此证书的签发者无效的解决方案
备注:第二个步骤一定要进行,否则弄到吐血,还是现实签发者无效 ---------------------- 1,按照你那个链接下载,https://developer.apple.com/certif ...
- Bash判断文件是否存在
#!/bin/bash if [ -f filename ]; then echo 'file exist' else echo 'file not exist' fi
- .NET设计模式(2):单件模式(Singleton Pattern)
转载:http://terrylee.cnblogs.com/archive/2005/12/09/293509.html 单件模式(Singleton Pattern) --.NET设计模式系列之二 ...
- 《你不常用的c#之四》:Array的小抽屉ArraySegment
转载自csdn:http://blog.csdn.net/robingaoxb/article/details/6200060 一:)略谈 ArraySegment顾名思义就是Array区块 ...
- Sql Server 2008 还原数据库 3154错误
sqlserver2008还原数据库时出现了3154错误,具体错误信息如下: 错误信息 The backup set holds a backup of a database other than t ...
- P次方数 英雄会 csdn 高校俱乐部
题目: 一个整数N,|N| >= 2, 如果存在整数x,使得N = x * x * x... (p个x相乘) =x^p,则称N是p次方数,给定32位内的整数N,求最大的P.例如N=5,输出1,N ...
- [学习笔记]设计模式之Composite
为方便读者,本文已添加至索引: 设计模式 学习笔记索引 写在前面 在Composite(组合)模式中,用户可以使用多个简单的组件以形成较大的组件,而这些组件还可能进一步组合成更大的.它重要的特性是能够 ...
- OPENCV
opencv_ts300.libopencv_world300.lib IlmImfd.lib libjasperd.liblibjpegd.liblibpngd.lib libtiffd.lib l ...
- Hierarchy Viewr 配合 adb 命令 查看窗口属性
Hierarchy Viewr 可以看到当前 的 窗口层次如下
- Day16 DOM &jQuery
一.本节主要内容 JavaScript 正则表达式 字符串操作的三个方法 DOM(知道就行,一般使用jQuery) 查找: 直接查找: document.getElementById 根据ID获取一个 ...