计算几何:按顺序给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    

problemId=696" style="color:blue; text-decoration:none">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. poj1418 Viva Confetti 判断圆是否可见

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Viva Confetti Time Limit: 1000MS   Memory ...

  2. poj 1418 Viva Confetti

    Viva Confetti Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1025   Accepted: 422 Desc ...

  3. uva 2572 Viva Confetti

    思路: 小圆面是由小圆弧围成.那么找出每条小圆弧,如果小圆弧,在小圆弧中点上下左右进行微小位移的所得的点一定在一个小圆面内. 找到最后覆盖这个小点的圆一定是可见的. 圆上的点按照相邻依次排序的关键量为 ...

  4. uva 1308 - Viva Confetti

    这个题目的方法是将圆盘分成一个个圆环,然后判断这些圆环是否被上面的圆覆盖: 如果这个圆的圆周上的圆弧都被上面的覆盖,暂时把它标记为不可见: 然后如果他的头上有个圆,他有个圆弧可见,那么他自己本身可见, ...

  5. UVaLive2572 poj1418 UVa1308 Viva Confetti

    一次放下n个圆 问最终可见的圆的数量 应该是比较经典的问题吧 考虑一个圆与其他每个圆的交点O(n)个 将其割成了O(n)条弧 那么看每条弧的中点 分别向内向外调动eps这个点 则最上面的覆盖这个点的圆 ...

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

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

  7. zoj 3537 区间dp+计算几何

    题意:给定n个点的坐标,先问这些点是否能组成一个凸包,如果是凸包,问用不相交的线来切这个凸包使得凸包只由三角形组成,根据costi, j = |xi + xj| * |yi + yj| % p算切线的 ...

  8. LA2572 Viva Confetti

    题意 PDF 分析 两两圆求交点,对每个圆弧按半径抖动. 时间复杂度\(O(T n^2)\) 代码 #include<iostream> #include<cstdio> #i ...

  9. [GodLove]Wine93 Tarining Round #9

    比赛链接: http://vjudge.net/contest/view.action?cid=48069#overview 题目来源: lrj训练指南---二维几何计算   ID Title Pro ...

随机推荐

  1. man pthread_mutex_init 或 man pthread_mutex_lock 没有结果的解决的方法

    问题: 在刚装好的 Mint/Ubuntu 可能会出现 man pthread_mutex 相关的函数没结果, 报No manual entry for pthread_mutex_init 的错误. ...

  2. Linux网络驱动程序

    Linux 的网络系统主要是基于 BSD UNIX 的套接字机制. 在系统与驱动程序之间定义了数据结构 sk_buff 进行传输数据.系统支持对发送数据和接收数据缓存,提供流控机制并提供对多协议的支持 ...

  3. 读配置文件能够保持顺序的 Java Properties 类

    序 前几天,公司项目中有一个需求是读取配置文件的.并且最好可以保证载入到内存中的顺序可以和配置文件里的顺序一致,可是.假设使用 jdk 中提供的 Properties 类的话,读取配置文件后.载入到内 ...

  4. 0x18 总结与练习

    这一章不太满意啊.. 还是有点痛苦,但就是做的挺慢啊... 1.就是例题 2.括号画家 感觉这种提高组类型的细节题都没什么信心啊,fail了几次才A #include<cstdio> #i ...

  5. 再续iOS开发中的这些权限

    前言 上篇文章iOS开发中的这些权限,你搞懂了吗?介绍了一些常用权限的获取和请求方法,知道这些方法的使用基本上可以搞定大部分应用的权限访问的需求.但是,这些方法并不全面,不能涵盖住所有权限访问的方法. ...

  6. 最大似然估计的缺陷 —— 方差和均值的 bias

    0. 均匀分布期望的最大似然估计 首先我们来看,如何通过最大似然估计的形式估计均匀分布的期望.均匀分布的概率密度函数为:f(x|θ)=1θ,0≤x≤θ.不失一般性地,将 x1,x2,-,xn 排序为顺 ...

  7. NESTED LOOPS & HASH JOIN & SORT MERGE JOIN

    表连接方式及使用场合 NESTED LOOP 对于被连接的数据子集较小的情况,nested loop连接是个较好的选择.nested loop就是扫描一个表,每读到一条记录,就根据索引去另一个表里面查 ...

  8. [C#] 隐式类型var —— 示例解析

    从 Visual C# 3.0 开始,在方法范围中声明的变量可以具有隐式类型var.隐式类型可以替代任何类型,它的具体类型由编译器根据上下文推断而出. 下面就让我来总结下隐式类型的一些特点: 1.va ...

  9. 5.文件I/O

    1 C标准函数与系统函数的区别 文件的结构体: 1.1 I/O缓冲区 每一个FILE文件流都有一个缓冲区buffer,默认大小8192Byte. 1.2 效率 文件缓冲区会降低效率.这里提供缓冲区主要 ...

  10. linux压缩(解压缩)命令详解

    一.tar命令          tar可以为文件和目录创建档案.利用tar,用户可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向档案中加入新的文件.tar 最初被用来在磁带上创 ...