HDU 1823 Luck and Love 二维线段树(树套树)
Luck and Love
Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5460 Accepted Submission(s): 1364
而是我在你面前
可你却不知道我爱你
―― 张小娴
前段日子,枫冰叶子给Wiskey做了个征婚启事,聘礼达到500万哦,天哪。但是天文数字了啊。不知多少MM蜂拥而至。顿时万人空巷,连扫地的大妈都来凑热闹来了。
―_―|||
因为人数太多。Wiskey实在忙只是来,就把统计的事情全交给了枫冰叶子,自己跑回家歇息去了。这可够枫冰叶子忙的了,他要处理的有两类事情,一是得接受MM的报名,二是要帮Wiskey查找符合要求的MM中缘分最高值。
接下来是一个操作符C。
当操作符为‘I’时,表示有一个MM报名,后面接着一个整数,H表示身高,两个浮点数。A表示活泼度。L表示缘分值。 (100<=H<=200, 0.0<=A,L<=100.0)
当操作符为‘Q’时,后面接着四个浮点数,H1。H2表示身高区间。A1,A2表示活泼度区间。输出符合身高和活泼度要求的MM中的缘分最高值。
(100<=H1,H2<=200, 0.0<=A1。A2<=100.0)
全部输入的浮点数,均仅仅有一位小数。
对查找不到的询问,输出-1。
8 I 160 50.5 60.0 I 165 30.0 80.5 I 166 10.0 50.0 I 170 80.5 77.5 Q 150 166 10.0 60.0 Q 166 177 10.0 50.0 I 166 40.0 99.9 Q 166 177 10.0 50.0 0
80.5 50.0 99.9
- //171MS 5900K
- #include<stdio.h>
- #include<algorithm>
- #define M 1007
- #define eps 1e-4
- using namespace std;
- char s[7];
- struct Sub_Tree
- {
- int left,right,ans;
- int mid(){return (left+right)>>1;}
- };
- struct Tree
- {
- int left,right;
- int mid(){return (left+right)>>1;}
- Sub_Tree subtree[4*M];
- }tree[M];
- void build_subtree(int l,int r,int i,int fa)
- {
- tree[fa].subtree[i].left=l;
- tree[fa].subtree[i].right=r;
- tree[fa].subtree[i].ans=-1;
- if(l==r)return;
- int mid=(l+r)>>1;
- build_subtree(l,mid,i<<1,fa);
- build_subtree(mid+1,r,i<<1|1,fa);
- }
- void build(int l,int r,int i)
- {
- tree[i].left=l;tree[i].right=r;
- build_subtree(0,1000,1,i);
- if(l==r)return;
- int mid=(l+r)>>1;
- build(l,mid,i<<1);
- build(mid+1,r,i<<1|1);
- }
- void up(int i,int fa)
- {
- tree[fa].subtree[i].ans=max(tree[fa].subtree[i<<1].ans,tree[fa].subtree[i<<1|1].ans);
- }
- void update_subtree(int a,int l,int i,int fa)
- {
- if(tree[fa].subtree[i].left==tree[fa].subtree[i].right)
- {
- tree[fa].subtree[i].ans=max(tree[fa].subtree[i].ans,l);
- return;
- }
- int mid=tree[fa].subtree[i].mid();
- if(a<=mid)update_subtree(a,l,i<<1,fa);
- else update_subtree(a,l,i<<1|1,fa);
- up(i,fa);
- }
- void update(int h,int a,int l,int i)
- {
- update_subtree(a,l,1,i);
- if(tree[i].left==tree[i].right)return;
- int mid=tree[i].mid();
- if(h<=mid)update(h,a,l,i<<1);
- else update(h,a,l,i<<1|1);
- }
- int query_subtree(int a1,int a2,int i,int fa)
- {
- if(tree[fa].subtree[i].left>=a1&&tree[fa].subtree[i].right<=a2)return tree[fa].subtree[i].ans;
- int mid=tree[fa].subtree[i].mid();
- int maxx=-1;
- if(a1<=mid)maxx=max(maxx,query_subtree(a1,a2,i<<1,fa));
- if(mid<a2)maxx=max(maxx,query_subtree(a1,a2,i<<1|1,fa));
- return maxx;
- }
- int query(int h1,int h2,int a1,int a2,int i)
- {
- if(tree[i].left>=h1&&tree[i].right<=h2)return query_subtree(a1,a2,1,i);
- int mid=tree[i].mid();
- int maxx=-1;
- if(h1<=mid)maxx=max(maxx,query(h1,h2,a1,a2,i<<1));
- if(mid<h2)maxx=max(maxx,query(h1,h2,a1,a2,i<<1|1));
- return maxx;
- }
- int main()
- {
- int t;
- while(scanf("%d",&t),t)
- {
- build(100,200,1);
- int h,h1,h2;
- double a,a1,a2,l;
- while(t--)
- {
- scanf("%s",s);
- if(s[0]=='I')
- {
- scanf("%d%lf%lf",&h,&a,&l);
- update(h,int(a*10),int(l*10),1);
- }
- else
- {
- scanf("%d%d%lf%lf",&h1,&h2,&a1,&a2);
- if(h1>h2)swap(h1,h2);
- if(a1>a2)swap(a1,a2);
- int maxx=query(h1,h2,int(a1*10),int(a2*10),1);
- if(maxx<0)printf("-1\n");
- else printf("%.1f\n",maxx/10.0);
- }
- }
- }
- return 0;
- }
HDU 1823 Luck and Love 二维线段树(树套树)的更多相关文章
- hdu 1823 Luck and Love 二维线段树
题目链接 很裸的题, 唯一需要注意的就是询问时给出的区间并不是l<r, 需要判断然后交换一下, WA了好多发... #include<bits/stdc++.h> using nam ...
- HDU1823 Luck ans Love 二维线段树
Luck and Love HDU - 1823 世界上上最远的距离不是相隔天涯海角 而是我在你面前 可你却不知道我爱你 ―― 张小娴 前段日子,枫冰叶子给Wiskey ...
- [hdu1823]Luck and Love(二维线段树)
解题关键:二维线段树模板题(单点修改.查询max) #include<cstdio> #include<cstring> #include<algorithm> # ...
- hdu 5465 Clarke and puzzle 二维线段树
Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- HDU 1823 Luck and Love(二维线段树)
之前只知道这个东西的大概概念,没具体去写,最近呵呵,今补上. 二维线段树 -- 点更段查 #include <cstdio> #include <cstring> #inclu ...
- hdu - 1823 - Luck and Love(线段树)
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/SCNU_Jiechao/article/details/24406391 题意:Wiskey招女友, ...
- HDU 4819 Mosaic(13年长春现场 二维线段树)
HDU 4819 Mosaic 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给定一个n*n的矩阵,每次给定一个子矩阵区域(x,y,l) ...
- Luck and Love(二维线段树)
Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu 4819 二维线段树模板
/* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...
随机推荐
- Druid 常见问题
https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98
- 【mybatis】mybatis访问报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 或者 feign被调用方使用的mybatis总报空指针异常java.lang.NullPointerException,而变量都没有问题的情况
mybatis访问报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 需要检查的步骤: ...
- frp, https, http, nginx 多服务, ssl等配置
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; # Add index.ph ...
- https://github.com/wytings
博客中写了很多比较杂乱的东西,有时候可能一时看不出效果,毕竟代码问题确实是 “Talk is cheap. Show me the code” 所以,就开了一个github,把一些日常开发和使用的工具 ...
- OpenCV图像平滑处理
图像平滑处理 目标 本教程教您怎样使用各种线性滤波器对图像进行平滑处理,相关OpenCV函数如下: blur GaussianBlur medianBlur bilateralFilter 原理 No ...
- POJ 3069 Saruman's Army
Saruman's Army Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6688 Accepted: 3424 De ...
- sqlserver 汉字转拼音
作者不详 --方法一sqlserver汉字转拼音首字母 --调用方法 select dbo.procGetPY ('中國') Create FUNCTION dbo.procGetPY ( ...
- iOS: 如何获取ios设备的当前IP地址
有的时候,我们项目上线后,需要根据ip地址去统计不同地区的用户情况,此时IP地址的收取显得尤其重要,一般情况下,在用户登录时去获取用户的ip是准确的,当然实时追踪ip的变化而统计是更安全可靠的. ip ...
- jquery点击click事件和blur事件冲突如何解决
最近做了一个查询小功能,input输入框输入文字后,自动列出几条查询结果,可以键盘上下键或鼠标进行查询结果选择,并且点击输入框其他地方要隐藏这个列出的结果. 但比较头疼的是input上添加blur事件 ...
- 触摸事件【MotionEvent】简介
MotionEvent简介 当用户触摸屏幕时,将创建一个MontionEvent对象,MotionEvent包含了关于发生触摸的位置.时间信息,以及触摸事件的其他很多细节. Android 将所有的输 ...