zoj2589Circles(平面图的欧拉定理)
连通图中:
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 55
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>; struct point
{
double x,y;
point(double x=,double y=):x(x),y(y){}
};
vector<point>ed[N];
vector<int>dd[N];
vector<point>td[N];
struct circle
{
point c;
double r;
point ppoint(double a)
{
return point(c.x+cos(a)*r,c.y+sin(a)*r);
}
};
circle cp[N],cq[N];
int fa[N];
typedef point pointt;
pointt operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
} int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
} bool operator == (const point &a,const point &b)
{
return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
}
double dis(point a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
double angle(point a)//计算向量极角
{
return atan2(a.y,a.x);
}
double sqr(double x) { return x * x; } bool intersection(const point& o1, double r1, const point& o2, double r2,int k,int kk)
{
double d = dis(o1- o2);
if (d < fabs(r1 - r2) - eps || d > r1 + r2 + eps)
{
return false;
}
double cosa = (sqr(r1) + sqr(d) - sqr(r2)) / ( * r1 * d);
double sina = sqrt(max(., . - sqr(cosa)));
point p1 = o1,p2 = o1;
p1.x += r1 / d * ((o2.x - o1.x) * cosa + (o2.y - o1.y) * -sina);
p1.y += r1 / d * ((o2.x - o1.x) * sina + (o2.y - o1.y) * cosa);
p2.x += r1 / d * ((o2.x - o1.x) * cosa + (o2.y - o1.y) * sina);
p2.y += r1 / d * ((o2.x - o1.x) * -sina + (o2.y - o1.y) * cosa);
//cout<<p1.x<<" --"<<p2.x<<" "<<o1.x<<" "<<o1.y<<" "<<o2.x<<" "<<o2.y<<endl;
//printf("%.10f %.10f %.10f %.10f\n",p1.x,p1.y,p2.x,p2.y);
ed[k].push_back(p1);
ed[k].push_back(p2);
ed[kk].push_back(p1);
ed[kk].push_back(p2); return true;
}
bool cmp(circle a, circle b)
{
if(dcmp(a.r-b.r)==)
{
if(dcmp(a.c.x-b.c.x)==)
return a.c.y<b.c.y;
return a.c.x<b.c.x;
}
return a.r<b.r;
}
bool cmpp(point a,point b)
{
if(dcmp(a.x-b.x)==)
return a.y<b.y;
return a.x<b.x;
}
int find(int x)
{
if(fa[x]!=x)
{
fa[x] = find(fa[x]);
return fa[x];
}
return x;
}
int main()
{
int t,i,j,n;
cin>>t;
while(t--)
{
scanf("%d",&n);
for(i = ; i <= n ;i++)
{
ed[i].clear();fa[i] = i;
dd[i].clear();
td[i].clear();
}
for(i = ; i <= n ;i++)
scanf("%lf%lf%lf",&cp[i].c.x,&cp[i].c.y,&cp[i].r);
sort(cp+,cp+n+,cmp);
int g = ;
cq[g] = cp[g];
for(i = ; i <= n; i++)
{
if(cp[i].c==cp[i-].c&&dcmp(cp[i].r-cp[i-].r)==)
continue;
cq[++g] = cp[i];
}
for(i = ; i <= g; i++)
{
for(j = i+ ; j <= g; j++)
{
int flag = intersection(cq[i].c,cq[i].r,cq[j].c,cq[j].r,i,j);
if(flag == ) continue;
int tx = find(i),ty = find(j);
fa[tx] = ty;
}
}
for(i = ; i <= g; i++)
{
int fx = find(i);
dd[fx].push_back(i);
}
int B=,V=;
int ans = ;
int num = ;
for(i = ; i <= g; i++)
{
if(dd[i].size()==) continue;
B = ,V = ;
for(j = ;j < dd[i].size() ; j++)
{
int u = dd[i][j];
if(ed[u].size()==)
{
B++;
continue;
}
sort(ed[u].begin(),ed[u].end(),cmpp);
td[i].push_back(ed[u][]);
int o = ;
for(int e = ; e < ed[u].size() ; e++)
{
//printf("%.10f %.10f\n",ed[u][e].x,ed[u][e].y);
td[i].push_back(ed[u][e]);
if(ed[u][e]==ed[u][e-]) continue;
else o++;
}
B+=o;
}
sort(td[i].begin(),td[i].end(),cmpp);
V+=;
// cout<<td[i].size()<<endl;
for(j = ; j < td[i].size() ; j++)
{
//printf("%.10f %.10f\n",td[i][j].x,td[i][j].y);
if(td[i][j]==td[i][j-]) continue;
else V++; }
// cout<<B+1-V<<" "<<B<<" "<<V<<endl;
ans+=B+-V;
}
cout<<+ans<<endl;
}
return ;
}
zoj2589Circles(平面图的欧拉定理)的更多相关文章
- LA 3263 (平面图的欧拉定理) That Nice Euler Circuit
题意: 平面上有n个端点的一笔画,最后一个端点与第一个端点重合,即所给图案是闭合曲线.求这些线段将平面分成多少部分. 分析: 平面图中欧拉定理:设平面的顶点数.边数和面数分别为V.E和F.则 V+F- ...
- Codeforces 1392I - Kevin and Grid(平面图的欧拉定理+FFT)
Codeforces 题面传送门 & 洛谷题面传送门 模拟赛考到一道和这题有点类似的题就来补了 神仙 GLBR I %%%%%%%%%%%%%%%%%%%% 不过感觉见过类似的题目之后就比较套 ...
- poj2284 That Nice Euler Circuit(欧拉公式)
题目链接:poj2284 That Nice Euler Circuit 欧拉公式:如果G是一个阶为n,边数为m且含有r个区域的连通平面图,则有恒等式:n-m+r=2. 欧拉公式的推广: 对于具有k( ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- [bzoj1997][Hnoi2010]Planar(2-sat||括号序列)
开始填连通分量的大坑了= = 然后平面图有个性质m<=3*n-6..... 由平面图的欧拉定理n-m+r=2(r为平面图的面的个数),在极大平面图的情况可以代入得到m=3*n-6. 网上的证明( ...
- ●POJ 2284 That Nice Euler Circuit
题链: http://poj.org/problem?id=2284 题解: 计算几何,平面图的欧拉定理 欧拉定理:设平面图的定点数为v,边数为e,面数为f,则有 v+f-e=2 即 f=e-v+2 ...
- NOIP2018 No regrets youth
NOIP2018在即,20181009总结一些易错的知识点和解题方法 ——by ljc20020730 HGOI NOIP2018 No regrets youth ! NOIP2018 No reg ...
- poj 2284 That Nice Euler Circuit 解题报告
That Nice Euler Circuit Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 1975 Accepted ...
- LA_3263_That_Nice_Euler_Circuits_(欧拉定理+计算几何基础)
描述 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=15& ...
随机推荐
- php中的curl】php中curl的详细解说
本文我来给大家详细介绍下cURL的简单的使用方法,下文我将会给大家详细介绍cURL的高级应用, cURL可以使用URL的语法模拟浏览器来传输数据, FTP, FTPS, HTTP, HTTPS, GO ...
- android的充电图标显示
最近RK3026的项目需要修改开机充电,才分析了Android原生态的充电过程. 充电的代码和图标在system/core/charger中,会编译成名字为charger的可执行文件,打包进ramdi ...
- css2---必须学的经典---定位问题
定位 position body<html<文档 定位是相对文档的 不是相对 body 或 html 1.position:relative 相对定位 a.不能使内嵌元素支持宽高 b. ...
- 周赛-KIDx's Pagination 分类: 比赛 2015-08-02 08:23 7人阅读 评论(0) 收藏
KIDx's Pagination Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) S ...
- 【20160924】GOCVHelper 图像增强部分(2)
//填充孔洞 //fillholes Mat fillHoles(Mat src){ Mat dst = getInnerHoles(src); ...
- uva 437,巴比伦塔
题目链接:https://uva.onlinejudge.org/external/4/437.pdf 题意:巴比伦塔: 给出n种立方体,一个立方体能放到另一个立方体上,必须满足,底面一定要小于下面的 ...
- volatile关键字解析
转载:http://www.cnblogs.com/dolphin0520/p/3920373.html volatile这个关键字可能很多朋友都听说过,或许也都用过.在Java 5之前,它是一个备受 ...
- vim退出
esc退出编辑模式 :wq 保存后退出vi :w 保存但不退出 :q 离开 vi :q! 若曾修改过档案,又不想储存,使用 ! 为强制离开不储存档案
- DateFormat 中间加别的字符
private static DateFormat dateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
- centos6.5用户添加到sudoers中
一.将用户添加到sudoers su vi /etc/sudoers :x! success 二.解释 su 目的是使用最高root权限去进行修改操作 vi /etc/sudoers 使用vi编辑器打 ...