poj 1418 Viva Confetti
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 1025 | Accepted: 422 |
Description
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
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
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的更多相关文章
- poj1418 Viva Confetti 判断圆是否可见
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Viva Confetti Time Limit: 1000MS Memory ...
- ZOJ 1696 Viva Confetti 计算几何
计算几何:按顺序给n个圆覆盖.问最后能够有几个圆被看见.. . 对每一个圆求和其它圆的交点,每两个交点之间就是可能被看到的圆弧,取圆弧的中点,往外扩展一点或者往里缩一点,从上往下推断有没有圆能够盖住这 ...
- POJ 1418 基本操作和圆 离散弧
Viva Confetti Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 761 Accepted: 319 Descr ...
- uva 2572 Viva Confetti
思路: 小圆面是由小圆弧围成.那么找出每条小圆弧,如果小圆弧,在小圆弧中点上下左右进行微小位移的所得的点一定在一个小圆面内. 找到最后覆盖这个小点的圆一定是可见的. 圆上的点按照相邻依次排序的关键量为 ...
- uva 1308 - Viva Confetti
这个题目的方法是将圆盘分成一个个圆环,然后判断这些圆环是否被上面的圆覆盖: 如果这个圆的圆周上的圆弧都被上面的覆盖,暂时把它标记为不可见: 然后如果他的头上有个圆,他有个圆弧可见,那么他自己本身可见, ...
- UVaLive2572 poj1418 UVa1308 Viva Confetti
一次放下n个圆 问最终可见的圆的数量 应该是比较经典的问题吧 考虑一个圆与其他每个圆的交点O(n)个 将其割成了O(n)条弧 那么看每条弧的中点 分别向内向外调动eps这个点 则最上面的覆盖这个点的圆 ...
- LA2572 Viva Confetti
题意 PDF 分析 两两圆求交点,对每个圆弧按半径抖动. 时间复杂度\(O(T n^2)\) 代码 #include<iostream> #include<cstdio> #i ...
- [GodLove]Wine93 Tarining Round #9
比赛链接: http://vjudge.net/contest/view.action?cid=48069#overview 题目来源: lrj训练指南---二维几何计算 ID Title Pro ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
随机推荐
- shell时间变量拼接问题
shell时间变量拼接问题 例1 ABC=ABC_`date –date='yesterday' "+%Y%m%d"`
- Java基础操作面试题:Map集合排序 需要TreeMap 构造方法参数有比较器 输入字符串,统计A、B、C、D、出现次数,由高到低输出字母和出现次数,使用Map集合完成此题
Map和Collections是同级别的,不能像List排序那样直接用Collections.sort(new Comparator<?>(){ 复写compara方法}); HashMa ...
- 使用js将div高度设置为100%
在开发的工程中使用到了一些开源的bootstrap模板进行开发,在遇到一些需要替换的内容部分部分时,经常出现高度设置100%无法生效的问题,这里来用js强行设置一下. 思路:js监听窗口的缩放 ...
- 洛谷 P1147 连续自然数和
洛谷 P1147 连续自然数和 看到dalao们的各种高深方法,本蒟蒻一个都没看懂... 于是,我来发一篇蒟蒻友好型的简单题解 #include<bits/stdc++.h> using ...
- SAP HANA
DROP PROCEDURE ""."ZCONCAT_EKKO_EBN"; CREATE PROCEDURE ""."ZCONCA ...
- 02Qt信号与槽(1)
信号与槽 1.概述 信号和槽机制是 Qt 的核心机制,信号和槽是一种高级接口,应用于对象之间的通信,它是 Qt 的核心特性,也是 Qt 区别于其他工具包的重要地方.信号和槽是 Qt 自行定义的一种 ...
- python 监控日志
#需求: #1.每分钟监控服务器日志,ip请求超过200次的,加入黑名单 #1.读文件,获取到每行的内容 open readlines # 178.210.90.90 - - [04/Jun/2017 ...
- python入门:if、elif、else 条件语句的基本用法
#!/usr/bin/env python # -*- coding:utf-8 -*- #elif(否则如果,译音:埃尔夫)eise(否则,译音:埃尔斯) #if.elif.else 条件语句的基本 ...
- thinkcmf5更新模板代码分析,解决模板配置json出错导致数据库保存的配置项内容丢失问题
private function updateThemeFiles($theme, $suffix = 'html') { $dir = 'themes/' . $theme; $themeDir = ...
- leepcode作业解析-5-21
25.Nim游戏 你和你的朋友,两个人一起玩 Nim 游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解. 编 ...