[codeforces 391D2]Supercollider
这题觉得似乎不难的样子……
但硬是没有做出来,真是不知说什么好喵~
注意到没有两条共线的线段具有公共点,没有重合的线段
说明每个十字形最多涉及一个水平线段和一个竖直线段
这说明我们可以二分了:每条线段两端砍掉delta长度后,有没有线段有公共点?
很水的扫描线吧~ 按 X 轴扫描,先把横的线段扫进去,再用竖的线段去查询
但是写法是很重要的,我说我不用线段树你信喵?我说我连离散化都不用你信喵?
#include <cstdio>
#include <algorithm>
#include <set>
const int size=; namespace IOspace
{
inline int getint()
{
register int num=;
register char ch=, last;
do last=ch, ch=getchar(); while (ch<'' || ch>'');
do num=num*+ch-'', ch=getchar(); while (ch>='' && ch<='');
if (last=='-') num=-num;
return num;
}
inline void putint(int num, char ch='\n')
{
char stack[];
register int top=;
if (num==) stack[top=]='';
for ( ;num;num/=) stack[++top]=num%+'';
for ( ;top;top--) putchar(stack[top]);
if (ch) putchar(ch);
}
} struct line
{
int x, y, l;
inline line() {}
inline line(int _x, int _y, int _l):x(_x), y(_y), l(_l) {}
};
struct node
{
int type;
int x, y1, y2;
inline node() {}
inline node(int _type, int _x, int _y1, int _y2):type(_type), x(_x), y1(_y1), y2(_y2) {}
inline bool operator < (node a) const {return x!=a.x?x<a.x:type*y2>a.type*a.y2;}
}; int n, m, k;
line h[size], s[size];
node q[size];
std::multiset<int> t;
inline int max(int x, int y) {return x>y?x:y;}
inline void swap(int & a, int & b) {int t=a; a=b; b=t;}
inline bool query(int, int);
inline bool check(int); int main()
{
n=IOspace::getint(); m=IOspace::getint();
for (int i=;i<n;i++) s[i].x=IOspace::getint(), s[i].y=IOspace::getint(), s[i].l=IOspace::getint();
for (int i=;i<m;i++) h[i].x=IOspace::getint(), h[i].y=IOspace::getint(), h[i].l=IOspace::getint(); int left=, right=, mid;
for (int i=;i<n;i++) right=max(right, s[i].l);
while (left+<right)
{
mid=(left+right)>>;
if (check(mid)) left=mid;
else right=mid;
} IOspace::putint(left); return ;
} inline bool query(int l, int r)
{
return t.lower_bound(l)!=t.upper_bound(r);
}
inline bool check(int d)
{
k=;
for (int i=;i<m;i++) if (h[i].l>=(d<<))
{
q[k++]=node(, h[i].x+d, h[i].y, );
q[k++]=node(, h[i].x+h[i].l-d, h[i].y, -);
}
for (int i=;i<n;i++) if (s[i].l>=(d<<))
q[k++]=node(, s[i].x, s[i].y+d, s[i].y+s[i].l-d);
std::sort(q, q+k);
t.clear();
for (int i=;i<k;i++)
{
if (q[i].type)
{
if (q[i].y2==) t.insert(q[i].y1);
else t.erase(t.find(q[i].y1));
}
else
if (query(q[i].y1, q[i].y2))
return true;
}
return false;
}
本傻受益匪浅系列
只存操作(包括插入、删除、询问)真是无比的高大上,跪跪跪
还有那鬼畜的查询写法
(set).lower_bound(l)!=(set).upper_bound(r)
可以查询 [l..r] 中是否有数存在,至于为什么这样是对的而不是别的样子了,大家在纸上画画就知道了吧
其实更好理解的是
当 (set).lower_bound(l)==(set).upper_bound(r) 时, [l..r] 中一定没有数
lower_bound是为了将 l 算入 [l..r] 中,upper_bound(r) 也是为了将 r 算入 [l..r] 中
真是跪跪跪跪跪跪跪跪
[codeforces 391D2]Supercollider的更多相关文章
- 【Codeforces Rockethon 2014】Solutions
转载请注明出处:http://www.cnblogs.com/Delostik/p/3553114.html 目前已有[A B C D E] 例行吐槽:趴桌子上睡着了 [A. Genetic Engi ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- windows8.1安装
不小心下载了英文版的windows8.1的操作系统,要添加中文语言,结果遇到不少问题. 第一:安装中文语言包: 可以在控制面板-添加语言中添加,这个方法好像只能在线更新,那速度,不能忍.还可以下载离线 ...
- Java知识结构思维导图
- 玩转渗透神器Kali:Kali Linux作为主系统使用的正确姿势TIPS
Kali Linux 前身是著名渗透测试系统BackTrack ,是一个基于 Debian 的 Linux 发行版,包含很多安全和取证方面的相关工具. 本文假设你在新装好的kali linux环境下… ...
- hadoop中Text类 与 java中String类的区别
hadoop 中 的Text类与java中的String类感觉上用法是相似的,但两者在编码格式和访问方式上还是有些差别的,要说明这个问题,首先得了解几个概念: 字符集: 是一个系统支持的所有抽象字符的 ...
- C#导入EXCEL数据
public static void InputUserFromExcel(string filePath) { string FileExName = filePath.Substring(file ...
- 一维条形码攻击技术(Badbarcode)
0x00 前言 在日常生活中,条形码随处可见,特别在超市,便利店,物流业,但你们扫的条形码真的安全吗?之前TK教主 在PacSec介绍的条形码攻击和twitter上的demo视频太炫酷,所以就自己买了 ...
- ASP.NET之Ajax系列(一)
我们在Web开发中经常会接触到Ajax技术,同时Ajax技术也有很多种实现方式,那么,我们今天从第一种方式说起:ASP.NET原生控件实现Ajax. ASP.NET原生控件用于Ajax技术的主要是Up ...
- 第一次进div1了
第一次进div1~好激动啊! 上帝依旧那么眷顾我!
- HDU 4819 Mosaic(13年长春现场 二维线段树)
HDU 4819 Mosaic 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给定一个n*n的矩阵,每次给定一个子矩阵区域(x,y,l) ...
- Word Ladder
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest t ...