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 ...
随机推荐
- Add margining capability to a dc/dc converter
You can easily add margining capability—that is, the ability to digitally adjust the output voltage— ...
- Low-cost ADC using only Digital I/O
http://letsmakerobots.com/node/13843 Reading A Sensor With Higher Accuracy – RC Timing Method RC Tim ...
- TRF7970A 天线
- 11.2 为什么要使用 MVC
以前的大部分应用程序(非Android应用)都是用像ASP.PHP或者CFML这样的过程化(自PHP5.0版本后已全面支持面向对象模型)语言来创建的.它们将像数据库查询语句这样的数据层代码和像HTML ...
- QT源码之Qt信号槽机制与事件机制的联系
QT源码之Qt信号槽机制与事件机制的联系是本文要介绍的内容,通过解决一个问题,从中分析出的理论,先来看内容. 本文就是来解决一个问题,就是当signal和slot的连接为Qt::QueuedConne ...
- C++中函数调用时的三种参数传递方式详解
在C++中,参数传递的方式是“实虚结合”. 按值传递(pass by value) 地址传递(pass by pointer) 引用传递(pass by reference) 按值传递的过程为:首先计 ...
- jquery操作CSS样式全记录
$(this).click(function(){ if($(this).hasClass(“zxx_fri_on”)){ $(this).removeClass(“zxx_fri_on”); ...
- Effective C++ 条款 50:了解new和delete的合理替换时机
(一) 为什么有人想要替换operator new 和 operator delete呢?三个常见的理由: (1)用来检測运用上的错误. (2)为了强化效果. (3)为了收集使用上的统计数据. (二) ...
- Was liberty资料总结
WebSphere Application Server Liberty Profile Guide for Developers: http://www.redbooks.ibm.com/redbo ...
- (剑指Offer)面试题43:n个骰子的点数
题目: 把n个骰子仍在地上,所有骰子朝上一面的点数之和为s.输入n,打印出s的所有可能的值出现的概率. 思路: s可能出现的值的范围为:n--6*n 1.全排列 回溯法枚举n个骰子(6面)的全排列,然 ...