hdu 1823 Luck and Love
2015-08-13 14:46
441 查看
二维线段树,写起来比较繁琐,难度并不大
#include<iostream> #include<cstdio> #define maxn 222 using namespace std; int h,hh; double a,b; struct stus { int l,r; double max; }; struct stu { int l,r; stus root[1111*4]; }; stu mapp[maxn*4]; void build2(int id,int l,int r,int count) { mapp[id].root[count].l=l; mapp[id].root[count].r=r; mapp[id].root[count].max=-1.0; if(l==r) return ; int mid=(l+r)/2; build2(id,l,mid,count*2); build2(id,mid+1,r,count*2+1); } void build(int l,int r,int ll,int rr,int count) { mapp[count].l=l; mapp[count].r=r; build2(count,ll,rr,1); if(l==r) return; int mid=(l+r)/2; build(l,mid,ll,rr,count*2); build(mid+1,r,ll,rr,count*2+1); } void updata2(int id,int count) { mapp[id].root[count].max=max(mapp[id].root[count].max,b); if(mapp[id].root[count].l==mapp[id].root[count].r) return; int mid=(mapp[id].root[count].l+mapp[id].root[count].r)/2; if(a<=mid) updata2(id,count*2); else updata2(id,count*2+1); } void updata(int count) { updata2(count,1); if(mapp[count].l==mapp[count].r) return; int mid=(mapp[count].l+mapp[count].r)/2; if(h<=mid) updata(count*2); else updata(count*2+1); } double que2(int l,int r,int id,int count) { //cout<<l<<"~"<<r<<endl; if(mapp[id].root[count].l==l&&mapp[id].root[count].r==r) return mapp[id].root[count].max; int mid=(mapp[id].root[count].l+mapp[id].root[count].r)/2; if(r<=mid) return que2(l,r,id,count*2); else if(l>=mid+1) return que2(l,r,id,count*2+1); else return max(que2(l,mid,id,count*2),que2(mid+1,r,id,count*2+1)); } double que(int l,int r,int count) { if(mapp[count].l==l&&mapp[count].r==r) return que2(a,b,count,1); int mid=(mapp[count].l+mapp[count].r)/2; if(r<=mid) return que(l,r,count*2); else if(l>=mid+1) return que(l,r,count*2+1); else return max(que(l,mid,count*2),que(mid+1,r,count*2+1)); } int main() { int n; while(cin>>n&&n) { build(100,200,0,1000,1); string cmd; for(int i=0;i<n;i++) { cin>>cmd; if(cmd=="I") { cin>>h>>a>>b; a*=10; updata(1); } else { cin>>h>>hh>>a>>b; if(h>hh) swap(h,hh);//坑 a*=10;b*=10; if(a>b) swap(a,b);//坑 if(que(h,hh,1)!=-1)printf("%.1f\n",que(h,hh,1)); else cout<<"-1"<<endl; } } } return 0; }
相关文章推荐
- Java post 请求
- HDU ACM 2010 水仙花数
- 浅谈 qmake 之 pro、pri、prf、prl文件
- 重新认识Segment fault
- 【AutoMapper官方文档】DTO与Domin Model相互转换(下)
- jquery.Validation.js使用手册,案例Demo
- MATLAB图像处理函数汇总(二)
- The connection to adb is down解决方案
- C#实现求一组数据众数的方法
- html5初始化时间控件
- Apache配置正向代理与反向代理
- 四个级别的 “自由” 程序员
- ajax与异步请求
- Sphinx介绍
- IP封包的封装 - 首部内容
- IP封包的封装 - 首部内容
- hdoj 5093 Battle ships 【二分图求最大匹配】【经典建图】
- 【AutoMapper官方文档】DTO与Domin Model相互转换(中)
- 解决jmeter报connection reset 错误的方法
- MATLAB图像处理函数汇总(一)