地址: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. 在linux上执行.net Console apps

    有个程序,在.net下写了半天,总算跑起来了,发现有个问题,在windows上不好弄,而同事前一段时间已经有Linux下的解决方法了,于是想直接将.net程序放在linux下运行 在linux上的mo ...

  2. VSCode集成TypeScript编译

    先安装github客户端和nodeJS客户端吧,直接去官网下载,nodeJS客户端安装完就集成了npm; 查看是否成功: git version  node -v npm-v 安装TypeScript ...

  3. np.tile 函数使用

    >>> import numpy>>> numpy.tile([0,0],5)#在列方向上重复[0,0]5次,默认行1次array([0, 0, 0, 0, 0, ...

  4. JavaEE JSP 学习笔记

    一.JSP简介 1.也是SUN公司推出的开发动态web资源的技术,属于JavaEE技术之一.由于原理上是Servlet, 所以JSP/Servlet在一起. 二.HTML.Servlet和JSP 1. ...

  5. 通过IFeatureClass 接口查询 IWorkspace, 查询通配符

    IWorkspace pWsI = ((IDataset)pFtCls).Workspace 查询通配符 ISQLSyntax psqls = (ISQLSyntax)(((IDataset)pFtC ...

  6. xtrabackup安装部署(二)

    在官网中,复制相关链接下载最新版本(建议使用当前发布版本前6个月左右的稳定版本) https://www.percona.com/downloads/XtraBackup/LATEST/ 1.下载和安 ...

  7. html 在一个超链接上面,鼠标移动上去时,也显示一串文字,如何实现

    a标签的title属性,对title属性赋值即可.例如:<a href="http://www.baidu.com/" title="跳转到百度"> ...

  8. 牛客网多校赛第9场 E-Music Game【概率期望】【逆元】

    链接:https://www.nowcoder.com/acm/contest/147/E 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...

  9. python数据结构之堆栈

    本篇我以堆栈的数据类型和操作方法两个方面总结学习笔记 堆栈(Stack) 一种后进先出(LIFO)的线性数据结构,对堆栈的插入和删除操作都只能在栈顶(top)进行. 堆栈可以通过数组和链表轻松实现 一 ...

  10. Ubuntu16.04下写的Qt程序,调试时没问题,运行时偶现崩溃 (需要在运行时生成core dump文件,QMAKE_CC += -g)

    记录一下 Ubuntu16.04下写的Qt程序,调试时没问题,运行时偶现崩溃 需要在运行时生成core dump文件 首先在pro结尾里加入 QMAKE_CC += -g QMAKE_CXX += - ...