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

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.

Input

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


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

3
0 0 0.5
-0.9 0 1.00000000001
0.9 0 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 题意及思路:具体可以参考《算法竞赛入门经典 训练指南》P269的分析。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cstring>
#include<string>
#include<functional>
#include<cmath>
#include<stack>
using namespace std;
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
double EPS = 4e-;
struct P {
double x, y;
P(double x=,double y=):x(x),y(y){}
};
vector<P>ps;
vector<double>r; int n; void clear() {
ps.clear();
r.clear();
}
//距离
double dist(const P&a,const P&b) {
return sqrt((a.x - b.x)*(a.x - b.x)+(a.y - b.y)*(a.y - b.y));//!!!!
} double normalize(double angel) {
while (angel < 0.0)angel += * pi;
while (angel >= * pi)angel -= * pi;
return angel;
} int find_circle(P p,const vector<P>& ps,const vector<double>r ) {//返回覆盖点p的最上面的圆的编号
for (int i = r.size()- ; i >= ;i--) {
if (dist(p, ps[i]) < r[i])
return i;
}
return -;
} void solve() {
vector<bool>visible(n, false);
for (int i = ; i < n;i++) {
vector<double>rads;//与其他圆相交的极角
rads.push_back(0.0);
rads.push_back( * pi);
for (int j = ; j < n;j++) {//找到与圆i相交的所有交点
double a = r[i];
double c = r[j];
double b = dist(ps[i], ps[j]);
if ( a + c < b ) // !!!!!!!
continue;
double theta = acos(double((a*a + b*b - c*c) /(2.0 * a*b)));
double phi = atan2(ps[j].y-ps[i].y,ps[j].x-ps[i].x);
rads.push_back(normalize(phi+theta));
rads.push_back(normalize(phi - theta));
} sort(rads.begin(), rads.end());
for (int j = ; j + < rads.size();j++) {//!!!!!
double rad;
rad = (rads[j] + rads[j + ]) / 2.0;
for (int k = -; k <= ;k+=) {//该点向园内圆外分别稍微移一下
int t=find_circle(P(ps[i].x+cos(rad)*(r[i]+k*EPS),ps[i].y+sin(rad)*(r[i]+k*EPS)),ps,r);
if (t != -)
visible[t] = true;
}
}
}
printf("%d\n",count(visible.begin(),visible.end(),true));
} int main() {
while (scanf("%d",&n)&&n) {
for (int i = ; i < n;i++) {
double x, y, z;
scanf("%lf%lf%lf",&x,&y,&z);
ps.push_back(P(x, y));
r.push_back(z);
} solve();
clear();
}
return ;
}

poj 1418 Viva Confetti的更多相关文章

  1. poj1418 Viva Confetti 判断圆是否可见

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

  2. ZOJ 1696 Viva Confetti 计算几何

    计算几何:按顺序给n个圆覆盖.问最后能够有几个圆被看见.. . 对每一个圆求和其它圆的交点,每两个交点之间就是可能被看到的圆弧,取圆弧的中点,往外扩展一点或者往里缩一点,从上往下推断有没有圆能够盖住这 ...

  3. POJ 1418 基本操作和圆 离散弧

    Viva Confetti Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 761   Accepted: 319 Descr ...

  4. uva 2572 Viva Confetti

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

  5. uva 1308 - Viva Confetti

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

  6. UVaLive2572 poj1418 UVa1308 Viva Confetti

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

  7. LA2572 Viva Confetti

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

  8. [GodLove]Wine93 Tarining Round #9

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

  9. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

随机推荐

  1. javaweb基础(13)_session防止表单重复提交

    在平时开发中,如果网速比较慢的情况下,用户提交表单后,发现服务器半天都没有响应,那么用户可能会以为是自己没有提交表单,就会再点击提交按钮重复提交表单,我们在开发中必须防止表单重复提交. 一.表单重复提 ...

  2. 【转】MFC编辑框自动换行,垂直滚动条自动下移

    1.新建一个编辑框控件(Edit Control),将其多行(Multiline)前面打勾(属性设置为True),Auto HScroll前面的勾去掉(属性设置False),这样就可以实现每一行填满后 ...

  3. 【差分约束】poj1275Cashier Employment

    比较经典的差分约束 Description A supermarket in Tehran is open 24 hours a day every day and needs a number of ...

  4. Windows 10 建立wifi热点

    如果当前是台式机那么需要一个usb的无线网卡,这里要注意如果你是使用台式机并且通过有线的方式上网,但是你的无线网卡适配器不能在禁用状态. 这里首先打开[运行]输入cmd,打开cmd(注意,这里要使用管 ...

  5. Leetcode5078. 负二进制数相加

    问题: 5078. 负二进制数相加 给出基数为 -2 的两个数 arr1 和 arr2,返回两数相加的结果. 数字以 数组形式 给出:数组由若干 0 和 1 组成,按最高有效位到最低有效位的顺序排列. ...

  6. linux三剑客正则表达式

    ^:以...开头,^d,意思是以d开头.例如:ls  -F(-p) | grep " ^d " $:以...结尾,/$,意思是以/结尾.例如:ls -F(-p) | grep &q ...

  7. PHPExcel探索之旅

    学习地址: https://www.imooc.com/video/8359 下载地址: https://packagist.org/packages/phpoffice/phpexcel 用comp ...

  8. 购物车小程序(while循环,列表)

    while True: salary = input("please input your salary:") if salary.isdigit(): salary=int (s ...

  9. github FATAL:unable to access 'https://github.com/...: Failed to connect to github.com:443; No error

    今天整理github,初次使用,很多都不懂,所以遇到了克隆失败的问题,研究了大半天,后来..... 打开Git Bash,克隆已有工程到本地: $ git clone https://github.c ...

  10. exe4j+Inno_setup打包java桌面应用

    打开exe4j,这里有个注意点,就是欢迎界面下面的License,如果没有请到网上找一个序列号,否则生成的exe打开之后都会先弹出您未激活exe4j的警告!点击下一步 这里有两个选项,第一个是通常编译 ...