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. SQLServer死锁

    死锁的四个必要条件:互斥条件(Mutual exclusion):资源不能被共享,只能由一个进程使用.请求与保持条件(Hold and wait):已经得到资源的进程可以再次申请新的资源.非剥夺条件( ...

  2. shell时间变量拼接问题

    shell时间变量拼接问题 例1 ABC=ABC_`date –date='yesterday' "+%Y%m%d"`

  3. lua在linxu和windows系统下的遍历目录的方法

    在windows下遍历目录使用lfs库:例如遍历整个目录下的所有文件 local lfs = require "lfs" function findPathName(path)  ...

  4. 浅谈JavaScript中的正则表达式(适用初学者观看)

    浅谈JavaScript中的正则表达式 1.什么是正则表达式(RegExp)? 官方定义: 正则表达式是一种特殊的字符串模式,用于匹配一组字符串,就好比用模具做产品,而正则就是这个模具,定义一种规则去 ...

  5. 一键生成属于自己的QQ历史报告,看看你对自己的QQ了解程度有多深?

    目录 一键生成属于自己的QQ历史报告,看看你对自己的QQ了解程度有多深? 简介 功能截图 如何运行 编写思路 main.py模块 qq_bot模块 tkinter_gui模块 static_data模 ...

  6. Huawei比赛数据分析

    如何评价2018年华为软件精英挑战赛赛题? https://www.zhihu.com/question/268448695 1.时间与时间戳之间的转换 https://blog.csdn.net/g ...

  7. 04_ThreadLocal整合事务操作

    文章导读: 本文主要讲解了如何在没有框架情况下如何解决Dao的事务问题, 重点理解Connection存放到WeakReference中为什么垃圾回收的时候Connection不回收 视频与源码下载: ...

  8. Linux下配置LAMP环境

    先准备相关软件,并确保服务器已经安装了gcc,gcc-c++,make三个软件,以便后续编译过程. 首先安装, libxml2 ftp://xmlsoft.org/libxml2/ 下载最新版本(我的 ...

  9. hexo博客发布注意事项

    最近把hexo博客内容写完了,就发布到github上面去,结果就出现各种一些小问题. 1.发布之后,hexo博客的css与js无法访问. 原因:没有配置正确的url路径.(配置文件_config.ym ...

  10. 到底有没有必要兼容IE版本

    我就说两个字:"没有". 理由如下: 1.占资源空间,额外去写css hack去做页面兼容处理.(主要是增加css代码) PS:css hack 不是W3C的规范,css hack ...