HDU 1823 二维线段树
2016-01-18 18:55
288 查看
HDU 1823
题目链接:
http://www.bnuoj.com/v3/problem_show.php?pid=5978
题意:
中文题
思路:
裸二维线段树,题目坑在输入部分已注释
源码:
题目链接:
http://www.bnuoj.com/v3/problem_show.php?pid=5978
题意:
中文题
思路:
裸二维线段树,题目坑在输入部分已注释
源码:
#include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <iostream> #include <string> using namespace std; const int MAXH = 100 + 5; const int MAXA = 1001 + 5; double tree[MAXH * 4][MAXA * 4]; char str[10]; void push_upx(int ox, int oy){tree[ox][oy] = max(tree[ox << 1][oy], tree[(ox << 1) | 1][oy]);} void push_upy(int ox, int oy){tree[ox][oy] = max(tree[ox][oy << 1], tree[ox][oy << 1 | 1]);} void updatey(int ox, int oy, int ly, int ry, int y, double val, int flag) { // printf("ox = %d, oy = %d, ly = %d, ry = %d\n", ox, oy, ly, ry); // system("pause"); if(ly == ry){ // printf("flag = %d\n", flag); if(flag) tree[ox][oy] = max(tree[ox][oy], val); else push_upx(ox, oy); } else{ int mid = (ly + ry) >> 1; if(y <= mid) updatey(ox, oy << 1, ly, mid, y, val, flag); else updatey(ox, oy << 1 | 1, mid + 1, ry, y, val, flag); push_upy(ox, oy); } } void updatex(int ox, int lx, int rx, int x, int y, double val) { // printf("ox = %d, lx =%d, rx = %d, x = %d, y = %d\n", ox, lx, rx, x, y); // system("pause"); if(lx != rx){ int mid = (lx + rx) >> 1; if(x <= mid) updatex(ox << 1, lx, mid, x, y, val); else updatex((ox << 1) | 1, mid + 1, rx, x, y, val); } updatey(ox, 1, 1, 1001, y, val, lx == rx); } double queryy(int ox, int oy, int ly, int ry, int y1, int y2) { if(ly >= y1 && ry <= y2) return tree[ox][oy]; int mid = (ly + ry) >> 1; double ans = -1; if(y1 <= mid) ans = max(ans, queryy(ox, oy << 1, ly, mid, y1, y2)); if(y2 > mid) ans = max(ans, queryy(ox, oy << 1 | 1, mid + 1, ry, y1, y2)); return ans; } double queryx(int ox, int lx, int rx, int x1, int x2, int y1, int y2) { if(lx >= x1 && rx <= x2) return queryy(ox, 1, 1, 1001, y1, y2); else{ int mid = (lx + rx) >> 1; double ans = -1; if(x1 <= mid) ans = max(ans, queryx(ox << 1, lx, mid, x1, x2, y1, y2)); if(x2 > mid) ans = max(ans, queryx(ox << 1 | 1, mid + 1, rx, x1, x2, y1, y2)); return ans; } } int main() { int m; while(scanf("%d", &m) != EOF && m){ for(int i = 0 ; i < 4 * MAXH ; i++) for(int j = 0 ; j < 4 * MAXA ; j++) tree[i][j] = -1; while(m--){ scanf("%s", str); if(str[0] == 'I'){ double h, a, l; scanf("%lf%lf%lf", &h, &a, &l); updatex(1, 1, 101, h - 99, a * 10 + 1, l); } else{ double h1, h2, a1, a2; scanf("%lf%lf%lf%lf", &h1, &h2, &a1, &a2); if(h1 > h2) swap(h1, h2); if(a1 > a2) swap(a1, a2); double ans = queryx(1, 1, 101, h1 - 99, h2 - 99, a1 * 10 + 1, a2 * 10 + 1); if(ans == -1.0) printf("-1\n"); else printf("%.1f\n", ans); } } } return 0; }
相关文章推荐
- HDU 4819 二维线段树
- 使用对象集合(通过Foundation框架使用OC处理字典,集合)
- 在使用jfreechart中需要注意的问题
- 数据泵--导入时自动创建用户
- Codeforces Gym 100531I Instruction 构造
- ubuntu中安装和卸载apache2、php、mysql
- POJ 2155 二维线段树
- 我的算法学习之路
- 算法导论第三版习题4.4
- s5pv210编译qt
- 获取文章的字数或则字符数
- 反编译[学习笔记]
- DEDE如何文章页调用相关文章列表
- cocos2d-x中ScrollView内的元素位置问题
- 通过Windows Media Player控件获取音频文件的时长
- 织梦安装时dede不能写入 怎么设置啊
- 孩子冷不冷?一指辨寒热!
- 操作符
- FSM(状态机)、HFSM(分层状态机)、BT(行为树)的区别
- 企业库判断数据库连接类型