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

Problem Description
世界上上最远的距离不是相隔天涯海角

而是我在你面前

可你却不知道我爱你

                ―― 张小娴



前段日子,枫冰叶子给Wiskey做了个征婚启事,聘礼达到500万哦,天哪。但是天文数字了啊。不知多少MM蜂拥而至。顿时万人空巷,连扫地的大妈都来凑热闹来了。

―_―|||

因为人数太多。Wiskey实在忙只是来,就把统计的事情全交给了枫冰叶子,自己跑回家歇息去了。这可够枫冰叶子忙的了,他要处理的有两类事情,一是得接受MM的报名,二是要帮Wiskey查找符合要求的MM中缘分最高值。

 
Input
本题有多个測试数据。第一个数字M。表示接下来有连续的M个操作,当M=0时处理中止。

接下来是一个操作符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)

全部输入的浮点数,均仅仅有一位小数。

 
Output
对于每一次询问操作,在一行里面输出缘分最高值。保留一位小数。

对查找不到的询问,输出-1。

 
Sample Input
  1. 8
  2. I 160 50.5 60.0
  3. I 165 30.0 80.5
  4. I 166 10.0 50.0
  5. I 170 80.5 77.5
  6. Q 150 166 10.0 60.0
  7. Q 166 177 10.0 50.0
  8. I 166 40.0 99.9
  9. Q 166 177 10.0 50.0
  10. 0
 
Sample Output
  1. 80.5
  2. 50.0
  3. 99.9
 
Author
威士忌
 
Source
 

二维线段树入门题。

第一维是高度,第二维是活泼度。
  1. //171MS 5900K
  2. #include<stdio.h>
  3. #include<algorithm>
  4. #define M 1007
  5. #define eps 1e-4
  6. using namespace std;
  7. char s[7];
  8. struct Sub_Tree
  9. {
  10. int left,right,ans;
  11. int mid(){return (left+right)>>1;}
  12. };
  13. struct Tree
  14. {
  15. int left,right;
  16. int mid(){return (left+right)>>1;}
  17. Sub_Tree subtree[4*M];
  18. }tree[M];
  19.  
  20. void build_subtree(int l,int r,int i,int fa)
  21. {
  22. tree[fa].subtree[i].left=l;
  23. tree[fa].subtree[i].right=r;
  24. tree[fa].subtree[i].ans=-1;
  25. if(l==r)return;
  26. int mid=(l+r)>>1;
  27. build_subtree(l,mid,i<<1,fa);
  28. build_subtree(mid+1,r,i<<1|1,fa);
  29. }
  30.  
  31. void build(int l,int r,int i)
  32. {
  33. tree[i].left=l;tree[i].right=r;
  34. build_subtree(0,1000,1,i);
  35. if(l==r)return;
  36. int mid=(l+r)>>1;
  37. build(l,mid,i<<1);
  38. build(mid+1,r,i<<1|1);
  39. }
  40.  
  41. void up(int i,int fa)
  42. {
  43. tree[fa].subtree[i].ans=max(tree[fa].subtree[i<<1].ans,tree[fa].subtree[i<<1|1].ans);
  44. }
  45.  
  46. void update_subtree(int a,int l,int i,int fa)
  47. {
  48. if(tree[fa].subtree[i].left==tree[fa].subtree[i].right)
  49. {
  50. tree[fa].subtree[i].ans=max(tree[fa].subtree[i].ans,l);
  51. return;
  52. }
  53. int mid=tree[fa].subtree[i].mid();
  54. if(a<=mid)update_subtree(a,l,i<<1,fa);
  55. else update_subtree(a,l,i<<1|1,fa);
  56. up(i,fa);
  57. }
  58.  
  59. void update(int h,int a,int l,int i)
  60. {
  61. update_subtree(a,l,1,i);
  62. if(tree[i].left==tree[i].right)return;
  63. int mid=tree[i].mid();
  64. if(h<=mid)update(h,a,l,i<<1);
  65. else update(h,a,l,i<<1|1);
  66. }
  67.  
  68. int query_subtree(int a1,int a2,int i,int fa)
  69. {
  70. if(tree[fa].subtree[i].left>=a1&&tree[fa].subtree[i].right<=a2)return tree[fa].subtree[i].ans;
  71. int mid=tree[fa].subtree[i].mid();
  72. int maxx=-1;
  73. if(a1<=mid)maxx=max(maxx,query_subtree(a1,a2,i<<1,fa));
  74. if(mid<a2)maxx=max(maxx,query_subtree(a1,a2,i<<1|1,fa));
  75. return maxx;
  76. }
  77.  
  78. int query(int h1,int h2,int a1,int a2,int i)
  79. {
  80. if(tree[i].left>=h1&&tree[i].right<=h2)return query_subtree(a1,a2,1,i);
  81. int mid=tree[i].mid();
  82. int maxx=-1;
  83. if(h1<=mid)maxx=max(maxx,query(h1,h2,a1,a2,i<<1));
  84. if(mid<h2)maxx=max(maxx,query(h1,h2,a1,a2,i<<1|1));
  85. return maxx;
  86. }
  87.  
  88. int main()
  89. {
  90. int t;
  91. while(scanf("%d",&t),t)
  92. {
  93. build(100,200,1);
  94. int h,h1,h2;
  95. double a,a1,a2,l;
  96. while(t--)
  97. {
  98. scanf("%s",s);
  99. if(s[0]=='I')
  100. {
  101. scanf("%d%lf%lf",&h,&a,&l);
  102. update(h,int(a*10),int(l*10),1);
  103. }
  104. else
  105. {
  106. scanf("%d%d%lf%lf",&h1,&h2,&a1,&a2);
  107. if(h1>h2)swap(h1,h2);
  108. if(a1>a2)swap(a1,a2);
  109. int maxx=query(h1,h2,int(a1*10),int(a2*10),1);
  110. if(maxx<0)printf("-1\n");
  111. else printf("%.1f\n",maxx/10.0);
  112. }
  113. }
  114. }
  115. return 0;
  116. }

HDU 1823 Luck and Love 二维线段树(树套树)的更多相关文章

  1. hdu 1823 Luck and Love 二维线段树

    题目链接 很裸的题, 唯一需要注意的就是询问时给出的区间并不是l<r, 需要判断然后交换一下, WA了好多发... #include<bits/stdc++.h> using nam ...

  2. HDU1823 Luck ans Love 二维线段树

    Luck and Love HDU - 1823 世界上上最远的距离不是相隔天涯海角 而是我在你面前 可你却不知道我爱你                 ―― 张小娴 前段日子,枫冰叶子给Wiskey ...

  3. [hdu1823]Luck and Love(二维线段树)

    解题关键:二维线段树模板题(单点修改.查询max) #include<cstdio> #include<cstring> #include<algorithm> # ...

  4. hdu 5465 Clarke and puzzle 二维线段树

    Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  5. HDU 1823 Luck and Love(二维线段树)

    之前只知道这个东西的大概概念,没具体去写,最近呵呵,今补上. 二维线段树 -- 点更段查 #include <cstdio> #include <cstring> #inclu ...

  6. hdu - 1823 - Luck and Love(线段树)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/SCNU_Jiechao/article/details/24406391 题意:Wiskey招女友, ...

  7. HDU 4819 Mosaic(13年长春现场 二维线段树)

    HDU 4819 Mosaic 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给定一个n*n的矩阵,每次给定一个子矩阵区域(x,y,l) ...

  8. Luck and Love(二维线段树)

    Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  9. hdu 4819 二维线段树模板

    /* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...

随机推荐

  1. Druid 常见问题

    https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98

  2. 【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) 需要检查的步骤: ...

  3. frp, https, http, nginx 多服务, ssl等配置

    server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; # Add index.ph ...

  4. https://github.com/wytings

    博客中写了很多比较杂乱的东西,有时候可能一时看不出效果,毕竟代码问题确实是 “Talk is cheap. Show me the code” 所以,就开了一个github,把一些日常开发和使用的工具 ...

  5. OpenCV图像平滑处理

    图像平滑处理 目标 本教程教您怎样使用各种线性滤波器对图像进行平滑处理,相关OpenCV函数如下: blur GaussianBlur medianBlur bilateralFilter 原理 No ...

  6. POJ 3069 Saruman&#39;s Army

    Saruman's Army Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6688   Accepted: 3424 De ...

  7. sqlserver 汉字转拼音

    作者不详       --方法一sqlserver汉字转拼音首字母 --调用方法 select dbo.procGetPY ('中國') Create FUNCTION dbo.procGetPY ( ...

  8. iOS: 如何获取ios设备的当前IP地址

    有的时候,我们项目上线后,需要根据ip地址去统计不同地区的用户情况,此时IP地址的收取显得尤其重要,一般情况下,在用户登录时去获取用户的ip是准确的,当然实时追踪ip的变化而统计是更安全可靠的. ip ...

  9. jquery点击click事件和blur事件冲突如何解决

    最近做了一个查询小功能,input输入框输入文字后,自动列出几条查询结果,可以键盘上下键或鼠标进行查询结果选择,并且点击输入框其他地方要隐藏这个列出的结果. 但比较头疼的是input上添加blur事件 ...

  10. 触摸事件【MotionEvent】简介

    MotionEvent简介 当用户触摸屏幕时,将创建一个MontionEvent对象,MotionEvent包含了关于发生触摸的位置.时间信息,以及触摸事件的其他很多细节. Android 将所有的输 ...