POJ 1418 Viva Confetti
来源:互联网 发布:nodejs 数组长度 编辑:程序博客网 时间:2024/05/01 13:04
Description
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.
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 decimal notation, with up to 12 digits after the decimal point. The imprecision margin is +/- 5 x 10^(-13). That is, it is guaranteed that variations of less than +/- 5 x 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.
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 decimal notation, with up to 12 digits after the decimal point. The imprecision margin is +/- 5 x 10^(-13). That is, it is guaranteed that variations of less than +/- 5 x 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
30 0 0.5-0.9 0 1.000000000010.9 0 1.0000000000150 1 0.51 1 1.000000000010 2 1.00000000001-1 1 1.000000000010 -0.00001 1.0000000000150 1 0.51 1 1.000000000010 2 1.00000000001-1 1 1.000000000010 0 1.0000000000120 0 1.00000010 0 120 0 10.00000001 0 10
Sample Output
35422
#include <iostream>#include <vector>#include <math.h>#include <set>#include <algorithm>using namespace std;#define PI acos(-1)#define eps 5e-13int 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 a) { return Point(c.x+r*cos(a),c.y+r*sin(a)); }}Cir[110];int dcmp(double x){ if(fabs(x)<eps)return 0; else return x<0?-1:1;}Point operator+(Point A,Point B){ return Point(A.x+B.x,A.y+B.y); }Point operator-(Point A,Point B){ return Point(A.x-B.x,A.y-B.y); }Point operator*(Point A,double p){ return Point(A.x*p,A.y*p); }Point operator/(Point A,double p){ return Point(A.x/p,A.y/p); }bool operator<(const Point&a,const Point&b){ return a.x<b.x||(a.x==b.x&&a.y<b.y); }bool operator == (const Point&a,const Point&b){ return dcmp(a.x-b.x)==0&&dcmp(a.x-b.x)==0; }double Dot(Point A,Point B){return A.x*B.x+A.y*B.y;}double Cross(Point A,Point B){return A.x*B.y-A.y*B.x;}double Length(Point A){return sqrt(Dot(A,A));}double angle(Point A){return atan2(A.y,A.x);}int getCircleCircleIntersection(Circle C1,Circle C2,vector<double> &sol){ double d=Length(C1.c-C2.c); if(dcmp(d)==0) { if(dcmp(C1.r-C2.r)==0)return -1; else return 0; } if(dcmp(C1.r+C2.r-d)<0)return 0; if(dcmp(fabs(C1.r-C2.r)-d)>0)return 0; double a=angle(C2.c-C1.c); double da=acos((C1.r*C1.r+d*d-C2.r*C2.r)/(2*C1.r*d)); sol.push_back(a-da); if(dcmp(da)) { sol.push_back(a+da); return 2; } else return 1;}int topmost(Point p){ int ans=-1; for(int i=N-1;i>=0;i--) if(Length(p-Cir[i].c)<Cir[i].r) { ans=i; break; } return ans;}int main(){ while(cin>>N&&N!=0) { for(int i=0;i<N;i++) cin>>Cir[i].c.x>>Cir[i].c.y>>Cir[i].r; set<int> ret; for(int i=0;i<N;i++) { vector<double> sol; for(int j=0;j<N;j++) getCircleCircleIntersection(Cir[i],Cir[j],sol); sol.push_back(0); sol.push_back(2.0*PI); sort(sol.begin(),sol.end()); int size=sol.size(); for(int j=0;j<size;j++) { double mid=(sol[j]+sol[j+1])/2; for(int d=-1;d<=1;d=d+2) { double r2=Cir[i].r+eps*d; Point p=Point(Cir[i].c.x+r2*cos(mid),Cir[i].c.y+r2*sin(mid)); int t=topmost(p); if(t>=0)ret.insert(t); } } } cout<<ret.size()<<endl; } return 0;}
0 0
- POJ 1418 Viva Confetti
- POJ 1418 Viva Confetti
- poj 1418 || zoj 1696 Viva Confetti
- POJ 1418 Viva Confetti(Japan 2002 Kanazawa)
- POJ 1418 Viva Confetti 已翻译
- LA - 2572 - Viva Confetti
- zoj 1696 Viva Confetti
- LA 2572 - Viva Confetti
- zoj 1696 Viva Confetti
- zoj 1696 Viva Confetti
- uva1308 Viva Confetti
- LA2572 Viva Confetti 计算几何
- ZOJ 1696 Viva Confetti 计算几何
- Viva Confetti(几何+圆盘覆盖问题)
- uva 1308 - Viva Confetti(几何)
- LA 2572 Viva Confetti 离散化 *
- LA 2572 Viva Confetti Kanazawa - 2002/2003 平面上的圆盘
- [gdc2011]Confetti Special Effects
- linux下的GDB调试
- Velocity(新手入门级---转载~)
- 组合数模p
- Javascript面向对象编程(三):非构造函数的继承
- 自定义 URL Scheme 完全指南
- POJ 1418 Viva Confetti
- 判断两个矩形是否相交的算法
- Java7的HashMap初始化变化
- GemFire核心功能介绍
- cocos2dx shader应用——sprite变灰
- Can We Do Better ?
- 一百行代码实现微信朋友圈九宫格图片显示
- 对象模型的细节
- 神州数码易拓TIPTOP ERP集成WEB应用(使用Flexigrid插件)