地址: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

Problem Description
To save Sara, Michael Scofield was captured by evil policemen and he was arrested in Prison again. As is known to all, nothing can stop Michael, so Prison Break continues.
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.

 
Input
There will be multiple test cases (no more than 10) in a test data.
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.
 
Output
The least number of walls to break for running out.
 
Sample Input
3
0 0 1
0 0 2
0 0 3
3
0 0 10
5 0 1
-5 0 1
 
Sample Output
3
2
 
Source

思路:

  圆的扫描。

  因为圆不相交,所以扫描线扫的时候可以成矩形来理解,扫描线上下圆的关系不变。

  并且扫到一个圆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 圆的扫描线的更多相关文章

  1. HDU5299 圆的扫描线 && 树上删边博弈

    HDU5299 圆的扫描线 && 树上删边博弈 标签(空格分隔): 未分类 给出若干个圆,可以互相嵌套但不相交或相切. 每次删去一个圆和它内部的圆,进行博弈,问谁赢. 分成两部分.首先 ...

  2. HDU 3681 Prison Break(BFS+二分+状态压缩DP)

    Problem Description Rompire is a robot kingdom and a lot of robots live there peacefully. But one da ...

  3. hdu 3681 Prison Break (TSP问题)

    Prison Break Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  4. hdu 3681 Prison Break(状态压缩+bfs)

    Problem Description Rompire . Now it’s time to escape, but Micheal# needs an optimal plan and he con ...

  5. Prison Break

    Prison Break 时间限制: 1 Sec  内存限制: 128 MB提交: 105  解决: 16[提交][状态][讨论版] 题目描述 Scofild又要策划一次越狱行动,和上次一样,他已经掌 ...

  6. HDU3681 Prison Break

    Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  7. 1254 - Prison Break

    1254 - Prison Break   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Mic ...

  8. hdu3511 圆的扫描线

    http://blog.csdn.net/firenet1/article/details/47041145 #include <iostream> #include <algori ...

  9. bzoj4561: [JLoi2016]圆的异或并 圆的扫描线

    地址:http://www.lydsy.com/JudgeOnline/problem.php?id=4561 题目: 4561: [JLoi2016]圆的异或并 Time Limit: 30 Sec ...

随机推荐

  1. Unity3D研究院之将UI的点击事件渗透下去(转)

    转自 http://www.xuanyusong.com/archives/4241 处理UI还有3D模型的点击推荐使用UGUI的这套事件系统,因为使用起来比较简洁,不需要自己用代码来发送射线,并且可 ...

  2. JavaAgent入门

    JavaAgent 是JDK 1.5 以后引入的,也可以叫做Java代理. JavaAgent 是运行在 main方法之前的拦截器,它内定的方法名叫 premain ,也就是说先执行 premain ...

  3. ios atomic nonatomic区别

    atomic和nonatomic用来决定编译器生成的getter和setter是否为原子操作.         atomic 设置成员变量的@property属性时,默认为atomic,提供多线程安全 ...

  4. CSS 盒子模型 二

    Sublime 快捷键: 文件保存后,输入 html:xt + tab  ,补全html html:xt <!DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...

  5. Pointer Lock

    Pointer Lock API 指针锁定(以前叫做 鼠标锁定) 提供了一种输入方法,这种方法是基于鼠标随着时间推移的运动的(也就是说,deltas),而不仅是鼠标光标的绝对位置.通过它可以访问原始的 ...

  6. HDU 2087 - 剪花布条 - [KMP算法]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2087 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...

  7. Chainer的初步学习

    人们都说Chainer是一块非常灵活you要用的框架,今天接着项目里面的应用,初步接触一下,涨涨姿势,直接上源码吧,看着好理解.其实跟Tensorflow等其他框架都是一个套路,个人感觉更简洁了. & ...

  8. The History of Operating Systems

    COMPPUTER SCIENCE AN OVERVIEW 11th Edition job 作业 batch processing 批处理 queue 队列 job queue 作业队列 first ...

  9. java---rce

    http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-app ...

  10. "context:annotation-config" and "context:component-scan"

    1.<context:annotation-config/>注册多个处理器 <context:annotation-config/>作用是向 Spring 容器注册 Autow ...