xiaoz 征婚,首先输入M,表示有M个操作。

借下来M行,对每一行   Ih a l     I 表示有一个MM报名,H是高度, a是活泼度,L是缘分。

或   Q h1 h2 a1 a2    求出身高在h1  h2  活泼度在a1  a2之间的最大缘分值。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <string>
  7. #include <vector>
  8. #include <stack>
  9. #include <queue>
  10. #include <set>
  11. #include <map>
  12. #include <list>
  13. #include <iomanip>
  14. #include <cstdlib>
  15. #include <sstream>
  16. using namespace std;
  17. typedef long long LL;
  18. const int INF=0x5fffffff;
  19. const double EXP=1e-;
  20. const int MS=;
  21.  
  22. struct active
  23. {
  24. int l,r;
  25. double maxv;
  26. int mid()
  27. {
  28. return (l+r)>>;
  29. }
  30. };
  31.  
  32. struct node
  33. {
  34. int l,r;
  35. active actives[*MS];
  36. int mid()
  37. {
  38. return (l+r)>>;
  39. }
  40. }nodes[];
  41.  
  42. void init()
  43. {
  44. for(int i=;i<;i++)
  45. for(int j=;j<*MS;j++)
  46. nodes[i].actives[j].maxv=-;
  47. }
  48.  
  49. void creat_a(int p,int root,int l,int r)
  50. {
  51. nodes[p].actives[root].l=l;
  52. nodes[p].actives[root].r=r;
  53. if(nodes[p].actives[root].l==nodes[p].actives[root].r)
  54. return ;
  55. int mid=(l+r)/;
  56. creat_a(p,root<<,l,mid);
  57. creat_a(p,root<<|,mid+,r);
  58. }
  59.  
  60. void creat(int root,int l,int r)
  61. {
  62. nodes[root].l=l;
  63. nodes[root].r=r;
  64. creat_a(root,,,MS);
  65. if(nodes[root].l==nodes[root].r)
  66. return ;
  67. int mid=(l+r)/;
  68. creat(root<<,l,mid);
  69. creat(root<<|,mid+,r);
  70. }
  71.  
  72. void insert_a(int p,int root,int pos,double value)
  73. {
  74. if(nodes[p].actives[root].maxv<value)
  75. nodes[p].actives[root].maxv=value;
  76. if(nodes[p].actives[root].l==nodes[p].actives[root].r)
  77. return ;
  78. if(pos<=nodes[p].actives[root].mid())
  79. insert_a(p,root<<,pos,value);
  80. else
  81. insert_a(p,root<<|,pos,value);
  82. }
  83.  
  84. void insert(int root,int pos,int value,double s)
  85. {
  86. insert_a(root,,value,s);
  87. if(nodes[root].l==nodes[root].r)
  88. return ;
  89. if(pos<=nodes[root].mid())
  90. insert(root<<,pos,value,s);
  91. else
  92. insert(root<<|,pos,value,s);
  93. }
  94.  
  95. double query_a(int p,int root,int l,int r)
  96. {
  97. double ans=-;
  98. if(nodes[p].actives[root].l>=l&&nodes[p].actives[root].r<=r)
  99. return nodes[p].actives[root].maxv;
  100. if(l<=nodes[p].actives[root].mid())
  101. ans= max(ans,query_a(p,root<<,l,r));
  102. if(r>nodes[p].actives[root].mid())
  103. ans=max(ans,query_a(p,root<<|,l,r));
  104. return ans;
  105. }
  106.  
  107. double query(int root,int l1,int r1,int l2,int r2)
  108. {
  109. double ans=-;
  110. if(nodes[root].l>=l1&&nodes[root].r<=r1)
  111. return query_a(root,,l2,r2);
  112. // 如果是叶子节点会在上一条语句中返回。
  113. if(l1<=nodes[root].mid())
  114. ans=max(ans,query(root<<,l1,r1,l2,r2));
  115. if(r1>nodes[root].mid())
  116. ans=max(ans,query(root<<|,l1,r1,l2,r2));
  117. return ans;
  118. }
  119.  
  120. int main()
  121. {
  122. int n,h1,h2;
  123. double a1,a2,fate;
  124. creat(,,);
  125. while(scanf("%d",&n)==&&n)
  126. {
  127. init();
  128. char cmd[MS];
  129. while(n--)
  130. {
  131. scanf("%s",cmd);
  132. if(cmd[]=='I')
  133. {
  134. scanf("%d %lf %lf",&h1,&a1,&fate);
  135.  
  136. insert(,h1,(int)(a1*+EXP),fate);
  137. }
  138. else
  139. {
  140. scanf("%d %d %lf %lf",&h1,&h2,&a1,&a2);
  141. if(h1>h2)
  142. swap(h1,h2);
  143. if(a1>a2)
  144. swap(a1,a2);
  145. double ans=query(,h1,h2,(int)(a1*+EXP),(int)(a2*+EXP));
  146. if(ans>=)
  147. printf("%.1lf\n",ans);
  148. else
  149. printf("-1\n");
  150. }
  151. }
  152. }
  153. return ;
  154. }

二维线段树 HDU 1823最简单的入门题的更多相关文章

  1. poj 2155:Matrix(二维线段树,矩阵取反,好题)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17880   Accepted: 6709 Descripti ...

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

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

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

    点击打开链接 Luck and Love Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

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

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

  5. hdu 4819 二维线段树模板

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

  6. HDU 4819 Mosaic (二维线段树)

    Mosaic Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total S ...

  7. HDU 4819 Mosaic --二维线段树(树套树)

    题意: 给一个矩阵,每次查询一个子矩阵内的最大最小值,然后更新子矩阵中心点为(Max+Min)/2. 解法: 由于是矩阵,且要求区间最大最小和更新单点,很容易想到二维的线段树,可是因为之前没写过二维的 ...

  8. HDU 4819 Mosaic 二维线段树

    Mosaic Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  9. HDU 4819 Mosaic (二维线段树&区间最值)题解

    思路: 二维线段树模板题,马克一下,以后当模板用 代码: #include<cstdio> #include<cmath> #include<cstring> #i ...

随机推荐

  1. c++ 概念及学习/c++ concept&learning(三)

    这一篇继续说说程序设计中的基本语句:控制块 一 if类控制语句 if if else if  , else if ,else if(条件语句){如果条件为真,要做的一些事情}  if(条件语句) {如 ...

  2. oc_转_构造对象的方法,以及类的继承

    一.构造方法 (一)构造方法的调用 完整的创建一个可用的对象:Person *p=[Person new]; New方法的内部会分别调用两个方法来完成2件事情: 1) 使用alloc方法来分配存储空间 ...

  3. Java-note-输入流

    java不像C中拥有scanf这样功能强大的函数,大多是通过定义输入输出流对象.常用的类有BufferedReader,Scanner.实例程序:一,利用 Scanner 实现从键盘读入integer ...

  4. Jquery类级别与对象级别插件开发

    jQuery插件的开发包括两种: 一种是类级别的插件开发,即给jQuery添加新的全局函数,相当于给jQuery类本身添加方法.jQuery的全局函数就是属于jQuery命名空间的函数,另一种是对象级 ...

  5. Argument 'xxx' is not a function, got undefined,初学Angular的第一个坑

    终于考完试了,在没更新的这一段时间里,一直都在忙于应付考试.不过在期间也是接触到不少好玩的东西,比如Html5的Canvas,我用lufylegend的Html5引擎做了个<看你有所色>的 ...

  6. Shell统计报表表格生成

    基本需求 分析完数据后,一般需要将数据以附件的形式发送处理,这个已经在<>中有介绍,如何 用Python实现附件的发送. 但不是所有人都关心附件的内容,一般邮件中需要有些概要的信息,如附件 ...

  7. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  8. STM32的GPIO使用的函数剖析

    转载http://blog.csdn.net/wuwuhuizheyisheng/article/details/8239599 STM32的GPIO总结 作者:JCY 该文是自己学习了一段STM32 ...

  9. IOS开发--数据持久化篇之文件存储(一)

    前言:个人觉得开发人员最大的悲哀莫过于懂得使用却不明白其中的原理.在代码之前我觉得还是有必要简单阐述下相关的一些知识点. 因为文章或深或浅总有适合的人群.若有朋友发现了其中不正确的观点还望多多指出,不 ...

  10. 最大流&最小割 - 专题练习

    [例1][hdu5889] - 算法结合(BFS+Dinic) 题意 \(N\)个点\(M\)条路径,每条路径长度为\(1\),敌人从\(M\)节点点要进攻\(1\)节点,敌人总是选择最优路径即最短路 ...