计算几何:按顺序给n个圆覆盖。问最后能够有几个圆被看见。。

对每一个圆求和其它圆的交点,每两个交点之间就是可能被看到的圆弧,取圆弧的中点,往外扩展一点或者往里缩一点,从上往下推断有没有圆能够盖住这个点,能盖住这个点的最上面的圆一定是可见的

Viva Confetti


Time Limit: 2 Seconds      Memory Limit: 65536 KB


Do you know confetti?

They are small discs of colored paper, and people throw them around during parties or festivals. Since people throw lots of confetti, they may end up stacked one on another, so there may be hidden ones underneath.

A handful of various sized confetti have been dropped on a table. Given their positions and sizes, can you tell us how many of them you can see?

The following figure represents the disc configuration for the first sample input, where the bottom disc is still visible.


Input

The input is composed of a number of configurations of the following form.

n
x1 y1 r1
x2 y2 r2
. . .
xn yn rn

The first line in a configuration is the number of discs in the configuration (a positive integer not more than 100), followed by one line descriptions of each disc: coordinates of its center and radius, expressed as real numbers in the decimal notation, with up to 12 digits after the decimal point. The imprecision margin is 5*10^-13. That is, it is guaranteed that variations of less than 5*10^-13 on input values do not change which discs are visible. Coordinates of all points contained in discs are between -10 and 10.

Confetti are listed in their stacking order, x1 y1 r1 being the bottom one and xn yn rn the top one. You are observing from the top.

The end of the input is marked by a zero on a single line.

Output

For each configuration you should output the number of visible confetti on a single line.

Sample Input

3
0 0 0.5
-0.9 0 1.00000000001
0.9 9 1.00000000001
5
0 1 0.5
1 1 1.00000000001
0 2 1.00000000001
-1 1 1.00000000001
0 -0.00001 1.00000000001
5
0 1 0.5
1 1 1.00000000001
0 2 1.00000000001
-1 1 1.00000000001
0 0 1.00000000001
2
0 0 1.0000001
0 0 1
2
0 0 1
0.00000001 0 1
0

Sample Output

3
5
4
2
2


Source: Asia 2002, Kanazawa (Japan)
Submit    Status

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>using namespace std;const double eps=5*(1e-13);
const double pi=acos(-1.0);int n;struct Point
{double x,y;Point(){}Point(double _x,double _y):x(_x),y(_y){}
};struct Circle
{Point c;double r;Circle(){}Circle(Point _c,double _r):c(_c),r(_r){}Point point(double x) {return Point(c.x+cos(x)*r,c.y+sin(x)*r);}
};double normal(double x)
{return x-floor(x/(2*pi))*2*pi;
}double dcmp(double x)
{if(fabs(x)<=eps) return 0;return (x<0)?

-1:1; } double DIST(Point a,Point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } Circle C[200]; double a[1000]; int tot=0; bool flag[110]; void check(Point x) { for(int i=n-1;i>=0;i--) { double d=DIST(x,C[i].c); if(dcmp(d-C[i].r)<0) { flag[i]=true; break; } } } int main() { while(scanf("%d",&n)!=EOF&&n) { memset(flag,0,sizeof(flag)); for(int i=0;i<n;i++) { double x,y,z; scanf("%lf%lf%lf",&x,&y,&z); C[i]=Circle(Point(x,y),z); } for(int i=0;i<n;i++) { tot=0; for(int j=0;j<n;j++) { if(i==j) continue; double dist=DIST(C[i].c,C[j].c); double ri=C[i].r,rj=C[j].r; if(dcmp(dist-ri-rj)>=0||dcmp(dist-fabs(ri-rj))<=0) continue; double t=atan2(C[j].c.y-C[i].c.y,C[j].c.x-C[i].c.x); double dt= acos((ri*ri+dist*dist-rj*rj)/(2.*ri*dist)); a[tot++]=normal(t+dt); a[tot++]=normal(t-dt); } a[tot++]=0;a[tot++]=2*pi; sort(a,a+tot); tot=unique(a,a+tot)-a; for(int j=0;j<tot-1;j++) { double u=(a[j]+a[j+1])/2; double r1=C[i].r+eps,r2=C[i].r-eps; Point p1=Point(C[i].c.x+r1*cos(u),C[i].c.y+r1*sin(u)); Point p2=Point(C[i].c.x+r2*cos(u),C[i].c.y+r2*sin(u)); check(p1); check(p2); } } int ans=0; for(int i=0;i<n;i++) if(flag[i]) ans++; printf("%d\n",ans); } return 0; }

ZOJ 1696 Viva Confetti 计算几何相关推荐

  1. POJ 1418 Viva Confetti 题解 《挑战程序设计竞赛》

    为什么80%的码农都做不了架构师?>>>    POJ 1418 Viva Confetti礼花:Confetti 是一些大小不一的彩色圆形纸片,人们在派对上.过节时便抛洒它们以示庆 ...

  2. Viva Confetti UVALive - 2572

    Viva Confetti UVALive - 2572 **离散化的思想,将每一个圆都分成一个个小圆弧 const int maxn = 100+10; Point center[maxn]; do ...

  3. ZOJ 3720 Magnet Darts (计算几何,概率,判点是否在多边形内)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3720 题意: 在一个矩形区域投掷飞镖,因此飞镖只会落在整点上,投到每个点的 ...

  4. [POJ1418]Viva Confetti

    题目大意 按照从底至顶的顺序给出平面上的 n n个圆(xi,yi,ri)(x_i,y_i,r_i),求从最顶上看能看到多少个圆. 一个测试点多组数据. 1≤n≤100,|xi|,|yi|∈[−10,1 ...

  5. ZOJ 2675 Little Mammoth(计算几何)

    圆形与矩形截面的面积 三角仍然可以做到这一点 代码: #include<stdio.h> #include<string.h> #include<stdlib.h> ...

  6. LA 2572 Viva Confetti (Geometry.Circle)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=problem_st ...

  7. Viva Confetti UVA - 1308

    思路:由于圆与圆相交的可见部分都是有圆弧组成的,枚举一个圆与其他圆的交点,对两交点所形成的圆弧,去判断该圆弧的中间点是否在其他圆内.若都不在,则证明该圆没有被完全遮住. #include <cs ...

  8. POJ 1418 Viva Confetti(Japan 2002 Kanazawa)

    点击打开链接 算法竞赛入门经典--训练指南 题目大意:n个圆盘依次放在桌面上,给出每个圆盘的坐标和圆心,求能看见的圆的个数; 分析:圆的每个可见部分由小圆弧围成,因此可以先求出所有小圆弧,然后判断每段 ...

  9. LA 2572 Viva Confetti 离散化 *

    题目地址:https://vjudge.net/problem/UVALive-2572 离散化:把每个圆看成是一段一段弧组成的 每个圆拿出来看一下,先求其上与其他所有圆的交点.每两个交点之间的那段弧 ...

最新文章

  1. Python 技巧篇-字符串灵活处理:字符串过滤、字符串拼接,字符串切片,特殊、超长字符串的处理实例演示
  2. 那些还在外包公司干的程序员们,快醒醒吧!
  3. 浏览器阻挡cookies_解决WordPress登录提示”Cookies被阻止或者您的浏览器不支持”...
  4. mysql还原数据库后日期显示3000_mysql 直接从date 文件夹备份表,还原数据库之后提示 table doesn`t exist的原因和解决方法...
  5. 05-传统开发模式DAO
  6. Megcup 2017 决赛第一题 规则
  7. [SVN] 分支同步、合入主干操作分享
  8. spring单元测试无法注入bean_Spring容器启动@Value属性无法注入?
  9. 多磁盘自动分区自动挂载脚本
  10. 预处理_关于食材预处理
  11. SharePoint 2010企业应用解决方案
  12. JDK 和 JRE 有什么区别
  13. SPSS分析数据学习笔记
  14. d3.js学习10----折线图的制作
  15. mysql 问号作用,在“WHERE column =?”中MySQL中问号的意义是什么?
  16. python3使用staf问题_转载—越来越强大的SAFS/STAF/STAX自动化测试框架
  17. SAP HANA是什么?
  18. PCM音频格式的深入理解
  19. 如何理解照片后期处理
  20. 交换机与路由器配置-利用OSPF协议实现网络互联

热门文章

  1. Java 8 简明教程
  2. atitit.软件开发方法总结O6
  3. C++输入输出进制、数据宽度与对齐、精度、取整
  4. 在 ubuntu 中设置安装 boost 库
  5. AAAI 2019 | 自动机器学习计算量大!这种多保真度优化技术是走向应用的关键
  6. 浏览器如何渲染页面?
  7. [机器学习]机器学习笔记整理12-线性回归概念理解
  8. 关于Android中的onCreate()多次被调用导致bindService被多次调用的问题...
  9. 一个初级程序员学习新技术的策略
  10. thinkphp mysql缓存_ThinkPhp数据缓存技术