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 ...
随机推荐
- Getaddrinfo()笔记
WSADATA dwRetval; if (WSAStartup(MAKEWORD(2,2),&dwRetval)!=0) //开启Socket { printf("WSAStart ...
- 高仿一元云购IOS应用源码项目
高仿一元云购IOS应用(高仿自一元云购安卓客户端) 本App因官方没有IOS客户端故开发,利用业务时间历时2个星期,终于开发完成,又因苹果的各大审核规则对此App的影响,又历时1个多月才终于成功上架, ...
- Spring MVC @ResponseBody返回中文字符串乱码问题
朋友做小项目练手的时候遇到的,着实让他郁闷够呛..这个问题的确很恶心.. 项目中引用的json包,直接用@ResponseBody注解返回json字符串..有关这个的乱码问题网上很多,各种花样各种转码 ...
- WinCE项目应用之虚拟仪器(VI)
虚拟仪器技术就是利用高性能的模块化硬件,结合高效灵活的软件来完成各种测试.测量和自动化的应用.虚拟测量仪器(VI)概念由美国国家仪器公司NI(National Instruments)提出,并引发了传 ...
- codevs哈希水题
1230 多重hash练习一下,不用也可以 // // main.cpp // codeves1230 // // Created by Candy on 9/29/16. // Copyright ...
- AC日记——字符串判等 openjudge 1.7 17
17:字符串判等 总时间限制: 1000ms 内存限制: 65536kB 描述 判断两个由大小写字母和空格组成的字符串在忽略大小写,且忽略空格后是否相等. 输入 两行,每行包含一个字符串. 输出 ...
- junit 测试及assert的扩张
@Testpublic void method() 测试注释指示该公共无效方法它所附着可以作为一个测试用例. @Beforepublic void method() Before注释表示,该方法必须在 ...
- 理解android.intent.action.MAIN 与 android.intent.category.LAUNCHER
刚才看了一下sundy的视频<LLY110426_Android应用程序启动>,里面讲到luncher这个activity通过获取应用程序信息来加载应用程序,显示给用户,其中就是通过一个应 ...
- TabBarController
1.两种方式创建系统TabBarController -(id)init{ self = [super init]; if( self ) { //newTask HSNewTaskViewContr ...
- 利用统计学知识为android应用的启动时间做数据分析
[声明:如需转载本文,请注明来源] 一.数据说明 启动时间用同一台设备,同一个包进行启动时间的测试,其中三组样本数据(每组100份对比数据)如下: 设备pro-5-1 base_list_1 = [0 ...