题意

PDF

分析

两两圆求交点,对每个圆弧按半径抖动。

时间复杂度\(O(T n^2)\)

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
    rg T data=0;
    rg int w=1;
    rg char ch=getchar();
    while(!isdigit(ch))
    {
        if(ch=='-')
            w=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        data=data*10+ch-'0';
        ch=getchar();
    }
    return data*w;
}
template<class T>T read(T&x)
{
    return x=read<T>();
}
using namespace std;
typedef long long ll;

co double eps=5e-13;

int dcmp(double x)
{
    if(fabs(x)<0)
        return 0;
    else
        return x<0?-1:1;
}

co double PI=acos(-1);

double NormalizeAngle(double rad,double center=PI)
{
    return rad-PI*2*floor((rad+PI-center)/(PI*2));
}

struct Point
{
    double x,y;

    Point(double x=0,double y=0)
    :x(x),y(y){}

    double angle()
    {
        return atan2(y,x);
    }
};
typedef Point Vector;

Vector operator+(Vector A,Vector B)
{
    return Vector(A.x+B.x,A.y+B.y);
}

Vector operator-(Point A,Point B)
{
    return Vector(A.x-B.x,A.y-B.y);
}

Vector operator*(Vector A,double p)
{
    return Vector(A.x*p,A.y*p);
}

Vector operator/(Vector A,double p)
{
    return Vector(A.x/p,A.y/p);
}

double Dot(Vector A,Vector B)
{
    return A.x*B.x+A.y*B.y;
}

double Length(Vector A)
{
    return sqrt(Dot(A,A));
}

void CircleCircleIntersection(Point c1,double r1,Point c2,double r2,vector<double>&rad)
{
    double d=Length(c1-c2);
    if(dcmp(d)==0)
        return;
    if(dcmp(r1+r2-d)<0)
        return;
    if(dcmp(fabs(r1-r2)-d)>0)
        return;

    double a=(c2-c1).angle();
    double da=acos((r1*r1+d*d-r2*r2)/(2*r1*d));
    rad.push_back(NormalizeAngle(a-da));
    rad.push_back(NormalizeAngle(a+da));
}

co int N=100;
int n;
Point center[N];
double radius[N];
bool vis[N];

int topmost(Point p)
{
    for(int i=n-1;i>=0;--i)
        if(dcmp(Length(center[i]-p)-radius[i])<0)
            return i;
    return -1;
}

int main()
{
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    while(read(n))
    {
        for(int i=0;i<n;++i)
            scanf("%lf %lf %lf",&center[i].x,&center[i].y,&radius[i]);
        fill(vis,vis+n,0);
        for(int i=0;i<n;++i)
        {
            vector<double>rad;
            rad.push_back(0);
            rad.push_back(PI*2);
            for(int j=0;j<n;++j)
                CircleCircleIntersection(center[i],radius[i],center[j],radius[j],rad);
            sort(rad.begin(),rad.end());

            for(int j=0;j<rad.size();++j)
            {
                double mid=(rad[j]+rad[j+1])/2;
                for(int side=-1;side<=1;side+=2)
                {
                    double r2=radius[i]-side*eps;
                    int t=topmost(Point(center[i].x+cos(mid)*r2,center[i].y+sin(mid)*r2));
                    if(t>=0)
                        vis[t]=1;
                }
            }
        }
        int ans=0;
        for(int i=0;i<n;++i)
            if(vis[i])
                ++ans;
        printf("%d\n",ans);
    }
    return 0;
}

LA2572 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. UVaLive2572 poj1418 UVa1308 Viva Confetti

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

  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. Python3,x:如何进行手机APP的数据爬取

    Python3,x:如何进行手机APP的数据爬取 一.简介 平时我们的爬虫多是针对网页的,但是随着手机端APP应用数量的增多,相应的爬取需求也就越来越多,因此手机端APP的数据爬取对于一名爬虫工程师来 ...

  2. Linux内核优化项

    net.ipv4.ip_forward = #该文件内容为0,表示禁止数据包转发,1表示允许 net.ipv4.conf.default.rp_filter = #是否忽略arp请求 net.ipv4 ...

  3. 用“倍增法”求最近公共祖先(LCA)

    1.最近公共祖先:对于有根树T的两个结点u.v,最近公共祖先LCA(T,u,v)表示一个结点x,满足x是u.的祖先且x的深度尽可能大. 2.朴素算法:记录下每个节点的父亲,使节点u,v一步一步地向上找 ...

  4. elasticsearch 拼音搜索

    现在很多公司都开始使用es来做搜索,我们公司目前也有好几个业务部门在用,我主要做商户搜索,为业务部门提供基础支持.上周把呼叫中心的搜索重新整理了下,在新增几个字段后,全量同步发现通过拼音首字母搜索无法 ...

  5. apache kafka配置中request.required.acks含义

    Kafka producer的ack有3中机制,初始化producer时的producerconfig可以通过配置request.required.acks不同的值来实现. 0:这意味着生产者prod ...

  6. java8 函数接口 Predicate例子

    import java.util.HashSet; import java.util.Collection; import java.util.function.Predicate; public c ...

  7. LeetCode 之 TwoSum

    题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...

  8. MySQL安装详解图文版(V5.5 For Windows)

    MySQL在Windows中会得到越来越广泛的应用.故整理MySQL安装详解如下,以备不时之需.安装环境:Windows Server 2003 [32bit NTFS]版本信息:MySQL 5.5. ...

  9. JNIjw02

    1.VC6(CPP)的DLL代码: #include<stdio.h> #include "jniZ_JNIjw02.h" JNIEXPORT void JNICALL ...

  10. 单网卡安装neutron

    devstack中机器只有一个物理网卡,如何设置neutron中的external网络? 方式是: 创建一个linux bridge和veth,把eth0和veth1加入到brige,用veth的另一 ...