地址: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. 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验十三:串口模块② — 接收

    实验十三:串口模块② - 接收 我们在实验十二实现了串口发送,然而这章实验则要实现串口接收 ... 在此,笔者也会使用其它思路实现串口接收. 图13.1 模块之间的数据传输. 假设我们不考虑波特率,而 ...

  2. [转] 基于TINY4412的Andorid开发-------简单的LED灯控制

    阅读目录 一.编写驱动程序 二.编写代码测试驱动程序 三.编写HAL代码 四.编写Framework代码 五.编写JNI代码 六.编写App 参考资料: <Andriod系统源代码情景分析> ...

  3. eclipse使用maven打包时去掉测试类

    eclipse使用maven打包时去掉测试类 在pom.xml文件中增加如下配置: <plugin> <groupId>org.apache.maven.plugins< ...

  4. iOS - Core Animation(核心动画)

    Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代码就可以实现非常强大的功能.Core An ...

  5. STM32下多串口用法

    一个项目用到32下的多个串口,一般STM32C8T6型号拥有3个USART,串口的配置都很简单,但是要使用的话就得解决他们之间的矛盾, printf函数到底输出在哪一个串口中? 先看这函数: //重定 ...

  6. Docker添加镜像加速器

    Docker默认pull连接镜像为国外镜像,速度较慢,注册阿里云可以生成一个镜像加速器 登录阿里云 https://cr.console.aliyun.com获取私有加速地址 修改配置文件/etc/d ...

  7. os.path 模块

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...

  8. MySQL在windows下的noinstall安装

    1.解压mysql zip软件包 2.配置环境变量 3.修改配置文件my_default.ini添加如下: [mysqld] basedir=D:\MySQL\MySQL Server 5.6(mys ...

  9. Python开发【笔记】:pymsyql 插入一条数据同时获取新插数据的自增id的两种方式

    一.通过cursor.lastrowid import pymysql.cursors # Connect to the database connection = pymysql.connect(h ...

  10. sql执行顺序与性能优化小技巧(一)

    关于sql条件匹配对执行效率影响测试 首先,创建一个标量函数create function ff_test() returns int as begin declare @i int=0 while( ...