LA2572 Viva Confetti
题意
分析
两两圆求交点,对每个圆弧按半径抖动。
时间复杂度\(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",¢er[i].x,¢er[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的更多相关文章
- poj1418 Viva Confetti 判断圆是否可见
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Viva Confetti Time Limit: 1000MS Memory ...
- poj 1418 Viva Confetti
Viva Confetti Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1025 Accepted: 422 Desc ...
- ZOJ 1696 Viva Confetti 计算几何
计算几何:按顺序给n个圆覆盖.问最后能够有几个圆被看见.. . 对每一个圆求和其它圆的交点,每两个交点之间就是可能被看到的圆弧,取圆弧的中点,往外扩展一点或者往里缩一点,从上往下推断有没有圆能够盖住这 ...
- uva 2572 Viva Confetti
思路: 小圆面是由小圆弧围成.那么找出每条小圆弧,如果小圆弧,在小圆弧中点上下左右进行微小位移的所得的点一定在一个小圆面内. 找到最后覆盖这个小点的圆一定是可见的. 圆上的点按照相邻依次排序的关键量为 ...
- uva 1308 - Viva Confetti
这个题目的方法是将圆盘分成一个个圆环,然后判断这些圆环是否被上面的圆覆盖: 如果这个圆的圆周上的圆弧都被上面的覆盖,暂时把它标记为不可见: 然后如果他的头上有个圆,他有个圆弧可见,那么他自己本身可见, ...
- UVaLive2572 poj1418 UVa1308 Viva Confetti
一次放下n个圆 问最终可见的圆的数量 应该是比较经典的问题吧 考虑一个圆与其他每个圆的交点O(n)个 将其割成了O(n)条弧 那么看每条弧的中点 分别向内向外调动eps这个点 则最上面的覆盖这个点的圆 ...
- [GodLove]Wine93 Tarining Round #9
比赛链接: http://vjudge.net/contest/view.action?cid=48069#overview 题目来源: lrj训练指南---二维几何计算 ID Title Pro ...
- POJ 1418 基本操作和圆 离散弧
Viva Confetti Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 761 Accepted: 319 Descr ...
- Thesis Viva checklist
This list gives you suggestions helpful in preparing to defend your thesis: I know my thesis thoroug ...
随机推荐
- HTML5抽奖转盘
在线演示 本地下载
- elasticsearch报错[WARN ][bootstrap ] Unable to lock JVM Memory: error=12,reason=Cannot allocate memory,解决
早上在服务器上安装elasticsearch集群,在其中的一台上面安装好elasticsearch之后安装了一些插件,其中一个插件是marvel,结果可能是新版本不支持这个插件,就没有安装成功,也就索 ...
- 解决 SMTP Error: Could not connect to SMTP host. 问题
我在使用PHPmailer发邮件时候,遇到了这个问题“SMTP Error: Could not connect to SMTP host.”,分享一下解决方法. 这个错误是PHP版本7产生的.如果我 ...
- 20145109 实验二 Java面向对象程序设计
实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 S.O.L.I.D原则: ...
- iOS 那些年我们遇到的坑
1坑: UITableView的第一个Cell下移
- E - Water Distribution
E - Water Distribution 题目大意: 有\(N\)座城市,给定这\(N\)座城市的坐标和初始的水量\(x_i,y_i,a_i\),在两个城市之间运水的花费是两个城市的欧几里得距离. ...
- 文件(1)--File
File简介 Java.io.File用于表示文件(目录),也就是说程序员可以通过File类在程序中操作硬盘上的文件和目录.File类只用于表示文件(目录)的信息(名称.大小等),不能对文件的内容进行 ...
- 通过案例说明struts2的工作流程
本文主要是通过一个例子来说明Struts2的一个工作流程. 首先定义一个登录页面login.jsp: [java] view plaincopy <%@ page language=" ...
- RENOUNCEMENT
I must not think of thee;and,tired yet syrong,I shun the thought that lurks in all delight--The thou ...
- MarkDown中锚的使用
经常使用Markdown配合Mou编辑器来些点总结和文档,但是其中需要前后引用或链接时markdown木有提供直接的方式.当然,Markdown支持嵌入式HTML语法,so..实现起来也没啥问题. 具 ...