一次放下n个圆

问最终可见的圆的数量

应该是比较经典的问题吧

考虑一个圆与其他每个圆的交点O(n)个

将其割成了O(n)条弧

那么看每条弧的中点 分别向内向外调动eps这个点 则最上面的覆盖这个点的圆可见O(n)

总时间复杂度O(n ** 3)

怕炸精度,代码基本抄的rjl的

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector> using namespace std; typedef double data_type; const data_type eps = * 1e-;
int dcmp(const data_type& x) {
if(fabs(x) < ) return ; return x < ? - : ;
} const data_type pi = acos(-1.0), dpi = * acos(-1.0); double NormalizeAngle(double rad) {
return rad - dpi * floor(rad / dpi);
} typedef const struct Point& Point_cr;
typedef struct Point {
data_type x, y;
Point() {}
Point(data_type x, data_type y) : x(x), y(y) {}
Point operator + (Point_cr rhs) const {
return Point(x + rhs.x, y + rhs.y);
}
Point operator - (Point_cr rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
Point operator * (data_type k) const {
return Point(x * k, y * k);
}
Point operator / (double k) const {
return Point(x / k, y / k);
}
double length() const {
return hypot(x, y);
}
double angle() const {
return atan2(y, x);
}
}Vector; double Dot(const Vector& v1, const Vector& v2) {
return v1.x * v2.x + v1.y * v2.y;
} double length(const Vector& v) {
return sqrt(Dot(v, v));
} typedef const Vector& Vector_cr;
void CircleCircleIntersection(Point_cr c1, double r1, Point c2, double r2, vector<double> &rad) {
double d = (c1 - c2).length();
if(dcmp(d) == ) return;
if(dcmp(r1 + r2 - d) < ) return;
if(dcmp(fabs(r1 - r2) - d) > ) return;
double a = (c2 - c1).angle();
double da = acos((r1 * r1 + d * d - r2 * r2) / ( * r1 * d));
rad.push_back(NormalizeAngle(a + da));
rad.push_back(NormalizeAngle(a - da));
} const int N = + ;
int n;
Point centre[N];
double radius[N];
bool vis[N]; int topmost(Point p) {
for(int i = n - ; i >= ; i--) {
if((centre[i] - p).length() < radius[i]) return i;
}
return -;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif while(scanf("%d", &n) == && n) {
for(int i = ; i < n; i++) {
double x, y, r;
scanf("%lf%lf%lf", &x, &y, &r);
centre[i] = Point(x, y);
radius[i] = r;
}
memset(vis, , sizeof vis);
for(int i = ; i < n; i++) {
vector<double> rad;
rad.push_back();
rad.push_back(dpi); for(int j = ; j < n; j++) {
CircleCircleIntersection(centre[i], radius[i], centre[j], radius[j], rad);
} sort(rad.begin(), rad.end()); for(unsigned j = ; j < rad.size(); j++) {
double mid = (rad[j] + rad[j+]) / 2.0;
for(int side = -; side <= ; side += ) {
double r2 = radius[i] - side * eps;
int t = topmost(Point(centre[i].x + cos(mid) * r2, centre[i].y + sin(mid) * r2));
if(t >= ) vis[t] = ;
}
}
}
int ans = ;
for(int i = ; i < n; i++) if(vis[i]) {
ans++;
}
printf("%d\n", ans);
} return ;
}

UVaLive2572 poj1418 UVa1308 Viva Confetti的更多相关文章

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

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

  2. poj 1418 Viva Confetti

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

  3. ZOJ 1696 Viva Confetti 计算几何

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

  4. uva 2572 Viva Confetti

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

  5. uva 1308 - Viva Confetti

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

  6. LA2572 Viva Confetti

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

  7. [GodLove]Wine93 Tarining Round #9

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

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

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

  9. Thesis Viva checklist

    This list gives you suggestions helpful in preparing to defend your thesis: I know my thesis thoroug ...

随机推荐

  1. 171. Excel Sheet Column Number(C++)

    171. Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as ...

  2. Linux下追踪函数调用,打印栈帧

    事情的起因是这样的,之前同事的代码有一个内存池出现了没有回收的情况.也就是是Pop出来的对象没有Push回去,情况很难复现,所以在Pop里的打印日志,跟踪是谁调用了它,我想在GDB调试里可以追踪调用的 ...

  3. 关于abbr 的一些用法

    <span style="margin: 20px;">位 000置:</span><abbr title='四川省绵阳市梓潼县文昌镇金龙乡一大队二组 ...

  4. javascript 一串DIV跟随鼠标移动

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  5. Ubuntu14.04不支持U盘exfat格式该如何解决

    转: http://www.jb51.net/os/Ubuntu/275158.html exfat是U盘的文件系统,很多系统都支持exfat格式的使用,但Ubuntu系统并不支持exfat格式,要如 ...

  6. 配置nginx支持thinkphp框架

    因为nginx本身没有支持pathinfo,所以无法使用thinkphp框架,不过我们可以在配置里进行修改使其能够正常使用thinkphp. 1.修改配置支持pathinfo vi /etc/ngin ...

  7. 抓取天涯文章的蜘蛛代码,刚经过更新(因为天涯页面HTML代码变化)

    #_*_coding:utf-8-*- import urllib2 import traceback import codecs from BeautifulSoup import Beautifu ...

  8. 【uva11374】Airport Express 最短路

    题意: 在Iokh市中,机场快线是市民从市内去机场的首选交通工具.机场快线分为经济线和商业线两种,线路,速度和价钱都不同.你有一张商业线车票,可以坐一站商业线,而其他时候只能乘坐经济线.假设换乘时间忽 ...

  9. php生成二维码,使用qrcode类库创建

    传说Google有个接口,可以生成二维码,这让我有点鸡冻不已,于是,......(省略1000字).结果,我找到了另外一个方法,是使用一个php类库,该工具叫:qrcode,但下载该工具可真是要人命. ...

  10. java中如何实现全局变量

    有时一个项目中会多处涉及到路径,当你把这个项目移植到别的电脑上时就要一一修改这些路径,过程十分繁琐,所以一个全局变量在这时是必不可少的. 遗憾的是java等oo语言并没有全局变量,这怎么办呢?下面介绍 ...