hdu-1823 Luck and Love
题目链接:hdu1823二维线段树单点更新区间查询
题意
向一个100*1000的二维空间中插入点,每次查询时,查询区间最大值.
题解
身高既然是100~200,那就相当于100;活泼度相当于1000.所以建立100*1000的二维线段树.
大坑有如下几个
输出-1,而不是-1.0
输入的h1,h2,a1,a2,大小不一定,需要加上一个判断
代码
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
typedef long long ll;
#define re(i,n) for(int i=0;i<n;i++)
const int maxn = 4;
const int xsz = 107, ysz = 1007;
double h,a, l;
double hf, ht, af, at;
double tr[(xsz+1)<<2][(ysz+1)<<2];
#define lson(id) id<<1,f,mid
#define rson(id) id<<1|1,mid+1,t
void yinsert(int x, int y, int f, int t){
tr[x][y] = max(tr[x][y], l);
if (f == t)return;
int mid = (f + t) >> 1;
if (a <= mid)yinsert(x, lson(y));
else yinsert(x, rson(y));
}
void xinsert(int id,int f,int t){
yinsert(id, 1, 0, ysz);
if (f == t)return;
int mid = (f + t) >> 1;
if (h <= mid)xinsert(lson(id));
else xinsert(rson(id));
}
void yquery(int x, int y, int f, int t){
if (af <= f&&at >= t){
l = max(l, tr[x][y]);
return;
}
int mid = (f + t) >> 1;
if (af <= mid)yquery(x, lson(y));
if (at > mid)yquery(x, rson(y));
}
void xquery(int x, int f, int t){
if (hf <= f&&ht >= t){
yquery(x, 1, 0, ysz);
return;
}
int mid = (f + t) >> 1;
if (ht > mid)xquery(rson(x));
if(hf<=mid) xquery(lson(x));
}
void yclear(int x, int y, int f, int t){
tr[x][y] = -1;
if (f == t)return;
int mid = (f + t) >> 1;
yclear(x, lson(y)), yclear(x, rson(y));
}
void xclear(int x, int f, int t){
yclear(x, 1, 0, ysz);
if (f == t)return;
int mid = (f + t) >> 1;
xclear(lson(x)), xclear(rson(x));
}
int main(){
freopen("in.txt", "r", stdin);
int Q;
while (scanf("%d", &Q) && Q){
xclear(1, 0, xsz);
while (Q--){
char op[2]; scanf("%s", op);
if (op[0] == 'I'){
scanf("%lf%lf%lf", &h, &a, &l);
h -= 100, a *= 10;
xinsert(1,0,xsz);
}
else{
scanf("%lf%lf%lf%lf", &hf, &ht, &af, &at);
hf -= 100, ht -= 100, af *= 10, at *= 10;
if (hf > ht)swap(hf, ht); if (af > at)swap(af, at);
l= -1;
xquery(1,0,xsz);
if (l == -1)puts("-1");
else printf("%.1lf\n", l);
}
}
}
return 0;
}
hdu-1823 Luck and Love的更多相关文章
- hdu - 1823 - Luck and Love(线段树)
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/SCNU_Jiechao/article/details/24406391 题意:Wiskey招女友, ...
- HDU 1823 Luck and Love 二维线段树(树套树)
点击打开链接 Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 1823 Luck and Love(二维线段树)
之前只知道这个东西的大概概念,没具体去写,最近呵呵,今补上. 二维线段树 -- 点更段查 #include <cstdio> #include <cstring> #inclu ...
- hdu 1823 Luck and Love 二维线段树
题目链接 很裸的题, 唯一需要注意的就是询问时给出的区间并不是l<r, 需要判断然后交换一下, WA了好多发... #include<bits/stdc++.h> using nam ...
- HDU 1823 Luck and Love (二维线段树&区间最值)题解
思路: 树套树,先维护x树,再维护y树,多练练应该就能懂了 代码: #include<cstdio> #include<cmath> #include<cstring&g ...
- HDU 1847-Good Luck in CET-4 Everybody!-博弈SG函数模板
Problem Description 大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Cici都是如此.当然,作为在考场浸润了十几载 ...
- HDU 5074 Luck Competition (暴力,概率)
题意:有 n 个人参加比赛,给出n-1个人的成绩,然后要选出一个幸运的人,先把所有的分数求平均数,然后再*2/3,那个不大于这个数,且最接近的数,就是最幸运的, 让你设置最后一个人的分,使他是最幸运的 ...
- 二维线段树 HDU 1823最简单的入门题
xiaoz 征婚,首先输入M,表示有M个操作. 借下来M行,对每一行 Ih a l I 表示有一个MM报名,H是高度, a是活泼度,L是缘分. 或 Q h1 h2 a1 a2 求 ...
- 【HDOJ】1823 Luck and Love
二维线段树.wa了几次,不存在输出-1,而不再是一位小数. #include <cstdio> #include <cstring> #define MAXN 105 #def ...
- HDU1823 Luck ans Love 二维线段树
Luck and Love HDU - 1823 世界上上最远的距离不是相隔天涯海角 而是我在你面前 可你却不知道我爱你 ―― 张小娴 前段日子,枫冰叶子给Wiskey ...
随机推荐
- ab.exe使用
ab.exe是一个性能检测工具,是apache server中的一个小组件,使用简单,方便 下载地址:http://files.cnblogs.com/files/gossip/ab.zi ...
- Apache
一.简介 Apache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一.它快速.可靠并且可通过简单的A ...
- HQL的一些语句总结
HQL原文来自:http://slaytanic.blog.51cto.com/2057708/782175/ Slaytanic老师 关于Hadoop的介绍来自:http://www.cnblo ...
- Hadoop2.6 datanode配置在线更新
datanode 的配置可以在线更新了,http://blog.cloudera.com/blog/2015/05/new-in-cdh-5-4-how-swapping-of-hdfs-datano ...
- cloudera cdh native lib
如果通过命令行的方式安装cloudera 版本的hadoop,下载它的cdh版本. 解压后执行,你会发现报warning,没有native的库,lib/native是空的. 如何获取native的文件 ...
- 用FineReport做的共建共享填报系统
一.应用背景 随着信息技术的不断发展,快速开发出适合用户业务需求发展的填报报表是势在必然的,因此在不断的研究和分析下针对这一业务特点制作了此报表系统,以使不同开发商之间共建共享数据进行填报和统计分析的 ...
- 理解 QEMU/KVM 和 Ceph(3):存储卷挂接和设备名称
本系列文章会总结 QEMU/KVM 和 Ceph 之间的整合: (1)QEMU-KVM 和 Ceph RBD 的 缓存机制总结 (2)QEMU 的 RBD 块驱动(block driver) (3)存 ...
- [转]C# 连接 Oracle 的几种方式
本文转自:http://www.cnblogs.com/storys/archive/2013/03/06/2945914.html 一:通过System.Data.OracleClient(需要安装 ...
- C#学习笔记-icon托盘图标的简单知识
在做整个类似QQ的毕业设计中,有一个小图标把我给难了一阵子,就是托盘小图标
- 1.使用using释放资源
using语句有二个关键字 >>作为关键字,using可以导入命名空间 >>作为C#语句,using可以释放对象占用的内存资源 语法: using(SqlConnection ...