hdu3511-Prison Break
纪念一下人生中第一道扫描线算法的题。。。。。其实不是严格上的第一道。。。第一次遇到的那个至今没过。。。。。
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=3511
这题应该算是扫描线的基础题。
对于每个圆,进入和出去的时候分别做扫描线,分别是x = c[i].x - c[i].r, x' = c[i].x + c[i].r;
这样对于每条扫描线,对于x',我们在集合中删去这个圆,这很好理解。
对于x,我们将这个圆加入集合,这样我们只要找向上第一个交的点和向下第一个交的点即可。
不过问题来了,这个交点坐标随着扫描线的移动是在变化的,但我们注意到,这些点的相对位置并不变(即上面的还在上面,下面的还在下面)
这样我们可以拉个set来维护扫描线上交点纵坐标,这个没必要存这个纵坐标的具体值,因为相对位置不变,树的结构也不变。
只需要重载一下小于号在insert时候使用即可。
如果扫描线向上或向下没有点,那么这个圆的depth = 1;
如果上下两个点属于同一个圆id,那么这个圆的depth = depth[id]+1;
如果上下两个圆属于不同的圆id1,id2,那么这个圆的depth = max(depth[id1], depth[id2]);
AC代码:
#include <bits/stdc++.h> using namespace std;
const int maxn = + ; typedef struct Circle{
int id, x, y, r; Circle( int id = , int x = , int y = , int r = ){
this->id = id;
this->x = x;
this->y = y;
this->r = r;
}
}Circle; Circle c[maxn]; typedef struct Point{
int id, ty; Point( int id = , int ty = ){
this->id = id;
this->ty = ty;
}
}Point; set<Point> s; typedef struct Line{
int id, x, ty; Line( int id = , int x = , int ty = ){
this->id = id;
this->x = x;
this->ty = ty;
} bool operator < ( const Line& l )const{
if( x == l.x )
return id < l.id;
return x < l.x;
}
}Line; Line l[maxn<<]; int depth[maxn]; int n, ans, xlog; double intersector( const Point& p ){
int id = p.id;
double r = 1.0*c[id].r; double x = 1.0*(xlog - c[id].x);
double y = sqrt((r*r - x*x)); if(p.ty == )
return 1.0*c[id].y + y;
else
return 1.0*c[id].y - y;
} bool operator < ( const Point& p1, const Point& p2 ){
if(p1.id == p2.id)
return p1.ty < p2.ty;
return intersector(p1) < intersector(p2);
} void solve( int nn ){
memset(depth, , sizeof(depth));
s.clear();
ans = ; for( int i = ; i < nn; ++i ){
int id = l[i].id, ty = l[i].ty;
xlog = l[i].x;
//cout << "id: " << id << " ty: " << ty << endl; if( ty == ){
s.erase(Point(id, ));
s.erase(Point(id, ));
}else{
s.insert(Point(id, ));
set<Point>::iterator it1 = s.find(Point(id, )), it2;
it2 = it1;
it2++; if( it1 == s.begin() || it2 == s.end() ){
depth[id] = ;
//cout << "id: " << id << " depth[id]: " << depth[id] << endl;
}else{
it1--;
if( it1->id == it2->id ){
depth[id] = depth[it1->id]+;
}else{
depth[id] = max( depth[it1->id], depth[it2->id] );
}
//cout << "id: " << id << " depth[id]: " << depth[id] << endl;
}
s.insert(Point(id, ));
}
ans = max( ans, depth[id]);
} printf("%d\n", ans);
} int main(void){
while(scanf("%d", &n) != EOF){
memset( c, , sizeof(c) );
memset( l, , sizeof(l) ); for( int i = ; i < n; ++i ){
c[i].id = i;
scanf("%d%d%d", &c[i].x, &c[i].y, &c[i].r);
l[i*] = Line(i, c[i].x-c[i].r, );
l[i*+] = Line(i, c[i].x+c[i].r, );
}
int nn = n * ;
sort( l, l + nn ); solve(nn);
} return ;
} /*
5
0 0 100
0 0 1
0 5 3
3 0 2
0 0 200
6
0 0 100
0 0 1
0 5 3
0 5 2
3 0 2
0 0 200
*/
hdu3511-Prison Break的更多相关文章
- hdu3511 Prison Break 圆的扫描线
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=3511 题目: Prison Break Time Limit: 10000/5000 MS ( ...
- HDU 3681 Prison Break(BFS+二分+状态压缩DP)
Problem Description Rompire is a robot kingdom and a lot of robots live there peacefully. But one da ...
- hdu 3681 Prison Break (TSP问题)
Prison Break Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- hdu 3681 Prison Break(状态压缩+bfs)
Problem Description Rompire . Now it’s time to escape, but Micheal# needs an optimal plan and he con ...
- Prison Break
Prison Break 时间限制: 1 Sec 内存限制: 128 MB提交: 105 解决: 16[提交][状态][讨论版] 题目描述 Scofild又要策划一次越狱行动,和上次一样,他已经掌 ...
- HDU3681 Prison Break
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- 1254 - Prison Break
1254 - Prison Break PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Mic ...
- HDU 3681 Prison Break(状态压缩dp + BFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 前些天花时间看到的题目,但写出不来,弱弱的放弃了.没想到现在学弟居然写出这种代码来,大吃一惊附加 ...
- hdu 3681 Prison Break
http://acm.hdu.edu.cn/showproblem.php?pid=3681 题意:一个n*m的矩阵,'F'是起点.机器人从F出发,走到G可以充电,走到Y关掉开关,D不能走进,要求把所 ...
- light oj 1254 - Prison Break 最短路
题目大意:n个点m条边的有向图,q次询问c,s,t,表示汽车邮箱容量为c,求从起点s到终点t的最小费用.汽车在每个点可以加任意的油,每个点的单位油价为a[i]. 题目思路:利用最小费优先队列优化最短路 ...
随机推荐
- java设计模式02观察者模式
观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态上发生变化时,会通知所有观察者对象,使它们能够自动更新自己. 这里主要讲一下学习内置观察者的记录,在JA ...
- 名词解释http隧道、https、SSL层、http代理、在线代理、socks代理区别
以前听到这几个名词时,总是搞混淆,今天花点时间来记录这几个名词的大概区别,方便以后自己查看. http隧道与https http隧道:“HTTP隧道技术”就是把所有要传送的数据全部封装到HTTP协议里 ...
- 测试edit中数据是否合法
void XyModal::OnEnKillfocusEdit1() { // TODO: 在此添加控件通知处理程序代码 CString cText; GetDlgItemText(IDC_EDIT1 ...
- picturebox中添加图片
private void Form1_Load(object sender, EventArgs e) { radioButton2.Checked = true; } private void ra ...
- redis中关于使用string类型还是hash类型
前篇:最近在做一个将redis中大数据量进行合并缩减优化的工作,其中一项按月将数据进行合并.将一个月的数据放入一个key-value键值对中. 例:p2d20180901-3.p2d20180902- ...
- tomcat 编码设置
在Tomcat8.0之前的版本,如果你要向服务器提交中文是需要转码的(如果你没有修改server.xml中的默认编码),因为8.0之前Tomcat的默认编码为ISO8859-1. POST方式提交 r ...
- webpack核心概念使用的综合小案例
注: 由于版本更新很快,同样的配置不同版本很可能会出错(这个就很绝望了) 解决思路 看文档 查看源码接口 网上搜索相应错误 环境 webpack4.x + yarn 文件结构 . ├── dist / ...
- 解决Scrapy抓取中文网页保存为json文件时中文不显示而是显示unicode的问题
注意:此方法跟之前保存成json文件的写法有少许不同之处,注意区分 情境再现: 使用scrapy抓取中文网页,得到的数据类型是unicode,在控制台输出的话也是显示unicode,如下所示 {'au ...
- odoo api介绍
odoo api修饰器介绍与应用 参考文档:https://www.cnblogs.com/kfx2007/p/6093994.html 一.one one的用法主要用于self为单一集合的情况,被o ...
- (问题待解决)sql查询不显示前置‘0’的问题
SELECT * , ,),() ) ' end)) from CourseBooksNotes ),)),)+'秒'; ),)),)),)+'秒'