poj1418 Viva Confetti 判断圆是否可见
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 881 | Accepted: 361 |
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
依照顺序摆放下n个圆,问最终有多少个圆是可见的。
想了好久,然后问了队友shu_mj,想了好一会才想通。
首先,可见部分的一部分的边界一定是圆弧。于是,我们可以先求出所有的圆相交划分的一小段一小段的圆弧,然后把这些小段圆弧的中点稍微往圆内移动一点以及往外移动一点。然后从后放的圆开始判断,最先出现在哪个圆中,那么这个圆就是可见的。
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author xyiyy @https://github.com/xyiyy
*/ #include <iostream>
#include <fstream> //#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype> using namespace std;
#define pb(X) push_back(X)
#define rep(X, N) for(int X=0;X<N;X++)
#define ALL(X) (X).begin(),(X).end() //
// Created by xyiyy on 2015/8/10.
// #ifndef JHELPER_EXAMPLE_PROJECT_P_HPP
#define JHELPER_EXAMPLE_PROJECT_P_HPP const double EPS = 4e-; double add(double a, double b) {
if (fabs(a + b) < EPS * (fabs(a) + fabs(b)))return ;
return a + b;
} class P {
public:
double x, y; P() { } P(double x, double y) : x(x), y(y) { } P operator+(const P &p) {
return P(add(x, p.x), add(y, p.y));
} P operator-(const P &p) {
return P(add(x, -p.x), add(y, -p.y));
} P operator*(const double &d) {
return P(x * d, y * d);
} P operator/(const double &d) {
return P(x / d, y / d);
} double dot(P p) {
return add(x * p.x, y * p.y);
} double abs() {
return sqrt(abs2());
} double abs2() {
return dot(*this);
} }; //求两圆的极角 以p为中心
double polarangle(P p, P q) {
return atan2(q.y - p.y, q.x - p.x);
} #endif //JHELPER_EXAMPLE_PROJECT_P_HPP const long double PI2 = * acos(-1.0); long double update(double x) {
while (x < 0.0)x += PI2;
while (x >= PI2)x -= PI2;
return x;
} class poj1418 {
public:
void solve(std::istream &in, std::ostream &out) {
int n;
P t;
while (in >> n && n) {
vector<P> ps;
vector<double> rs;
vector<bool> cansee(n, );
rep(i, n) {
double x, y, r;
in >> x >> y >> r;
ps.pb(P(x, y));
rs.pb(r);
}
rep(i, n) {
vector<double> pp;
pp.pb(0.0);
pp.pb(PI2);
rep(j, n) {
double a = rs[i];
double d = (ps[i] - ps[j]).abs();
double b = rs[j];
if (a + b < d || a + d < b || b + d < a)continue;
double theta = acos((a * a + d * d - b * b) / ( * a * d));
double alpha = polarangle(ps[i], ps[j]);
pp.pb(update(alpha - theta));
pp.pb(update(alpha + theta));
}
sort(ALL(pp));
rep(j, pp.size() - ) {
double theta = (pp[j] + pp[j + ]) / ;
for (int k = -; k <= ; k += ) {
t.x = ps[i].x + (rs[i] + k * EPS) * cos(theta);
t.y = ps[i].y + (rs[i] + k * EPS) * sin(theta);
int gao = n - ;
for (; gao >= ; gao--) {
if ((ps[gao] - t).abs() < rs[gao])break;
}
if (gao != -)cansee[gao] = ;
}
}
}
out << count(ALL(cansee), ) << endl;
}
}
}; int main() {
std::ios::sync_with_stdio(false);
std::cin.tie();
poj1418 solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return ;
}
代码君
poj1418 Viva Confetti 判断圆是否可见的更多相关文章
- poj 1418 Viva Confetti
Viva Confetti Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1025 Accepted: 422 Desc ...
- ZOJ 1696 Viva Confetti 计算几何
计算几何:按顺序给n个圆覆盖.问最后能够有几个圆被看见.. . 对每一个圆求和其它圆的交点,每两个交点之间就是可能被看到的圆弧,取圆弧的中点,往外扩展一点或者往里缩一点,从上往下推断有没有圆能够盖住这 ...
- uva 1308 - Viva Confetti
这个题目的方法是将圆盘分成一个个圆环,然后判断这些圆环是否被上面的圆覆盖: 如果这个圆的圆周上的圆弧都被上面的覆盖,暂时把它标记为不可见: 然后如果他的头上有个圆,他有个圆弧可见,那么他自己本身可见, ...
- A Round Peg in a Ground Hole - POJ 1584 (判断凸多边形&判断点在多边形内&判断圆在多边形内)
题目大意:首先给一个圆的半径和圆心,然后给一个多边形的所有点(多边形按照顺时针或者逆时针给的),求,这个多边形是否是凸多边形,如果是凸多边形在判断这个圆是否在这个凸多边形内. 分析:判断凸多边形可 ...
- 判断圆和矩形是否相交C - Rectangle and Circle
Description Given a rectangle and a circle in the coordinate system(two edges of the rectangle are p ...
- HDU 1221 Rectangle and Circle(判断圆和矩形是不是相交)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1221 Rectangle and Circle Time Limit: 2000/1000 MS (J ...
- POJ1584 A Round Peg in a Ground Hole 凸包判断 圆和凸包的关系
POJ1584 题意:给定n条边首尾相连对应的n个点 判断构成的图形是不是凸多边形 然后给一个圆 判断圆是否完全在凸包内(相切也算) 思路:首先运用叉积判断凸多边形 相邻三条边叉积符号相异则必有凹陷 ...
- UVaLive2572 poj1418 UVa1308 Viva Confetti
一次放下n个圆 问最终可见的圆的数量 应该是比较经典的问题吧 考虑一个圆与其他每个圆的交点O(n)个 将其割成了O(n)条弧 那么看每条弧的中点 分别向内向外调动eps这个点 则最上面的覆盖这个点的圆 ...
- POJ 1584 /// 判断圆(点)在多边形内 判断凸包
题目大意: 给定n,n边形 给定圆钉的 半径r 和圆心(x,y) 接下来n行是n边形的n个顶点(顺时针或逆时针给出) 判断n边形是否为凸包 若不是输出 HOLE IS ILL-FORMED 判断圆心和 ...
随机推荐
- php中magic_quotes_gpc函数详解
magic_quotes_gpc函数在php中的作用是判断解析用户提示的数据,如包括有:post.get.cookie过来的数据增加转义字符“\”,以确保这些数据不会引起程序,特别是数据库语句因为特殊 ...
- Spark保存到HDFS或本地文件相关问题
spark中saveAsTextFile如何最终生成一个文件 http://www.lxway.com/641062624.htm 一般而言,saveAsTextFile会按照执行task的多少生成多 ...
- 解决jsp页面乱码问题
页面也需要设置转码的:页面:(.jsp) <%@ page language="java" import="java.util.*" pageEncodi ...
- head命令
head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾. 1.命令格式: hea ...
- 设计模式 ( 十八 ):State状态模式 -- 行为型
1.概述 在软件开发过程中,应用程序可能会根据不同的情况作出不同的处理.最直接的解决方案是将这些所有可能发生的情况全都考虑到.然后使用if... ellse语句来做状态判断来进行不同情况的处理.但是对 ...
- Linux内核定时器
Linux使用struct timer_list来描述一个定时器. 重要成员: expires:定时时长 *function:超时执行函数名使用流程: 1.定义定时器变量 /*定义定时器变量结构 ...
- sicily 4379 bicoloring
题意:输入一个简单(无多重边和自环)的连通无向图,判断该图是否能用黑白两种颜色对顶点染色,使得每条边的两个端点为不同颜色. 解法:由于无自连通节点存在,所以只需进行一次宽搜,遍历所有的点和所有的边,判 ...
- ios 限制输入长度
----------------UITextField限制输入的长度------------ - (BOOL)textField:(UITextField *)textField shouldChan ...
- http断点续传原理:http头 Range、Content-Range
所谓断点续传,也就是要从文件已经下载的地方开始继续下载.在以前版本的 HTTP 协议是不支持断点的,HTTP/1.1 开始就支持了.一般断点下载时才用到 Range 和 Content-Range 实 ...
- Jmeter接口测试案例实践(一)
1.1. 接口介绍 本次测试的接口采用内网中的通讯录查询接口进行测试,接口参数如下: 1.2. 使用Jmeter进行接口测试 1.2.1. 打开Jmeter 下载好Jmeter后,双击bin目录下的j ...