hdu3511 Prison Break 圆的扫描线
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=3511
题目:
Prison Break
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2149 Accepted Submission(s): 681
The prison consists of many circular walls. These walls won't intersect or tangent to each other.

Now Michael is arrested in one of the deepest rooms, and he wants to know how many walls he has to break at least for running out. In figure 1, Michael has to break 3 walls at least and in figure 2, 2 walls are needed.
For each test case, the first line contains one number: n (1<=n<=50,000) indicating the total number of circular walls.
Then n lines follow, each line contains three integers x, y, r. (x,y) indicates the center of circular wall and r indicates the radius of the wall.
-100,000<=x,y<=100,000
1 <= r <= 100,000
The input ends up with EOF.
0 0 1
0 0 2
0 0 3
3
0 0 10
5 0 1
-5 0 1
2
思路:
圆的扫描。
因为圆不相交,所以扫描线扫的时候可以成矩形来理解,扫描线上下圆的关系不变。
并且扫到一个圆k,他的上面的圆为up,下面的为dw。
if(up==dw&&up!=0) deep[k]=deep[up]+1;
else if(up||dw) deep[k]=max(deep[up],deep[dw]);
else deep[k]=1;
至于是为什么的话,自己多画画就知道了。
还有,set并没真正存圆和扫描线的交点,因为扫描线在变交点也在变。
set中的交点是cmp时动态求的,这还有点巧妙的。
#include <bits/stdc++.h> #define MP make_pair using namespace std; const double eps = 1e-;
const int N = 1e5+; int n,cnt[N];
int cr[N][],r[N];
pair<int,int>pt[N];
double curx; struct node
{
int id,f;
bool operator < (const node &ta) const
{
double y1 = cr[id][] + f * sqrt(1.0 *r[id]*r[id]-1.0*(curx-cr[id][])*(curx-cr[id][]));
double y2 = cr[ta.id][] + ta.f * sqrt(1.0 *r[ta.id]*r[ta.id]-1.0*(curx-cr[ta.id][])*(curx-cr[ta.id][]));
if(fabs(y1-y2)<eps)
return f<ta.f;
return y1<y2;
}
};
set<node >st; int main(void)
{
int n;
while(~scanf("%d",&n))
{
st.clear();
int tot=,ans=;
for(int i=;i<=n;i++)
{
scanf("%d%d%d",&cr[i][],&cr[i][],r+i);
pt[tot++]=MP(cr[i][]-r[i],i);
pt[tot++]=MP(cr[i][]+r[i],i-n);
cnt[i]=;
}
sort(pt,pt+tot);
for(int i=;i<tot;i++)
{
int k=pt[i].second,up=,dw=;
curx = pt[i].first;
if(k<=)
k+=n,st.erase((node){k,-}),st.erase((node){k,});
else
{
auto it=st.insert((node){k,-}).first;
it++;
if(it!=st.end()) up = it->id;
it--;
if(it!=st.begin()) dw = (--it)->id;
if(up==dw&&up)
ans=max(ans,cnt[k]=cnt[up]+);
else if(up&&dw)
ans=max(ans,cnt[k]=max(cnt[up],cnt[dw]));
else
cnt[k]=;
st.insert((node){k,});
}
}
printf("%d\n",ans);
} return ;
}
hdu3511 Prison Break 圆的扫描线的更多相关文章
- HDU5299 圆的扫描线 && 树上删边博弈
HDU5299 圆的扫描线 && 树上删边博弈 标签(空格分隔): 未分类 给出若干个圆,可以互相嵌套但不相交或相切. 每次删去一个圆和它内部的圆,进行博弈,问谁赢. 分成两部分.首先 ...
- 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 ...
- hdu3511 圆的扫描线
http://blog.csdn.net/firenet1/article/details/47041145 #include <iostream> #include <algori ...
- bzoj4561: [JLoi2016]圆的异或并 圆的扫描线
地址:http://www.lydsy.com/JudgeOnline/problem.php?id=4561 题目: 4561: [JLoi2016]圆的异或并 Time Limit: 30 Sec ...
随机推荐
- [Key] RegCure Pro
Serial RegCure Pro : 4A803-C4F23-422B6-1F3D6 http://www.paretologic.com/product/regcure-pro/
- vuejs学习资料
Vue.js 是一个轻巧.高性能.可组件化的MVVM库,同时拥有非常容易上手的API,让编写动态的UI界面变得轻松简单. 这里是我整理的相关学习资料: vue.js 中文api vue.js gith ...
- 微信小程序---示例DEMO
转:CSDN的文章: https://blog.csdn.net/rolan1993/article/details/73467867 不错的DEMO: https://github.com/skyv ...
- ABP之应用服务(2)
在上一篇的笔记中,已经大致对Application层的使用作了简要的使用说明,感觉还是有些东西需要研究一下,所以承接上文,对AutoMapper这个方便的东西,稍微研究一下. 一.初识AutoMapp ...
- 洞察行业领先者的前沿思想——第五届TOP100全球软件案例研究峰会精彩谢幕
(第五届TOP100summit开幕式现场) 12月09日-12日,由msup主办的第五届TOP100全球软件案例研究峰会(以下简称TOP100summit)在北京国家会议中心举行,作为互联网行业最有 ...
- HDU-2680 Choose the best route 单向边+反向dijkstra
https://vjudge.net/problem/HDU-2680 题意:以起始点 终点 长度 给出一个图,已知可以从w个起点出发,求从任一起点到同一个终点s的最短路径.注意是单向边.m<1 ...
- Python的浅拷贝与深拷贝
定义: =号浅拷贝:在Python中对象的赋值其实就是对象的引用.copy了之后两个仍然是同一个东西.那么他们内部的元素自然也是一样的,对其中一个进行修改,另一个也会跟着变> copy()浅拷贝 ...
- iOS多线程编程之创建线程(转载)
一.创建和启动线程简单说明 一个NSThread对象就代表一条线程 (1)创建.启动线程 NSThread *thread = [[NSThread alloc] initWithTarget:sel ...
- kafka配置文件注解
若advertised.host.name的值是aa,则kafka发布的服务名也要是aa kafka log.cleanup.policy=delete 日志清理策略 log.retention.ho ...
- jquery中的ajax方法参数的用法和他的含义:
转自:https://www.cnblogs.com/huiyuantang/p/5458278.html 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.ty ...