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

最新文章

  1. fstream使用简介
  2. C# MailMessage Attachment 中文名附件发邮件-Firefox中文显示正常,网页打开邮件附件中文名乱码
  3. 实战:ASP.NET MVC中把Views下面的视图放到Views文件夹外
  4. Android 学习笔记多媒体技术之 Drawable类+Tween(补间动画)+Frame(帧动画)
  5. 将“Cocos2dx-截屏并设置图片尺寸 ”中cocos2d-x代码转换为2.2的代码
  6. JavaScript日常会跳的坑系列(二)
  7. Binary Tree Paths 解答
  8. 整理的 matplotlib 绘图笔记
  9. 用VS2015写一个简单的ASP.net网站
  10. Java之IO流学习总结【下】
  11. (NO.00002)iOS游戏精灵战争雏形(八)
  12. string format的各类格式及用法
  13. 【原创】大叔经验分享(21)yarn中查看每个应用实时占用的内存和cpu资源
  14. 修复ogg source端意外宕机造成的数据不同步
  15. java 模拟登录新浪微博(通过cookie)
  16. oracle11g忘记sys密码
  17. Gridview 单选效果实现,且用且珍惜
  18. 全屏幕显示AVI
  19. 除掉inline-block 间距
  20. sql server下划线查询

热门文章

  1. C语言递归练习
  2. CentOS 配置Rails开发环境
  3. html、css如何画实心圆
  4. python开发环境搭建(windows+python2.7.5+django1.5.4)【原创】
  5. 0003python中的可变参数
  6. 2018/03/09 每日一学PHP 之 require_once require include include_once 包含文件的区别
  7. IO流(10)复制多级文件夹
  8. Bug笔记:Google Map第一次缩放位置偏移
  9. ovs的主要代码函数及大体结构图
  10. Gson的两种解析用法