• 题目
  • 题意:首先给定一个以原点为圆心,R为半径的圆,之后在给m个圆,这些圆可能会和原来的圆有所交集,计算开始的圆剩余区域的周长,不包括内部周长。
  • 首先判定两圆关系,如果内含,直接加上圆的周长,如果相交,在计算对应弧长,其他情况都不用计算。在计算圆心角的时候,有个精度问题,只用本身半径算出来的弧度会不够,所有用上两个圆的半径。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
const double PI = acos(-1.0);
typedef struct point {
double x;
double y;
point() { }
point(double a, double b) {
x = a;
y = b;
}
point operator -(const point &b)const { //返回减去后的新点
return point(x - b.x, y - b.y);
}
point operator +(const point &b)const { //返回加上后的新点
return point(x + b.x, y + b.y);
}
//数乘计算
point operator *(const double &k)const { //返回相乘后的新点
return point(x * k, y * k);
}
point operator /(const double &k)const { //返回相除后的新点
return point(x / k, y / k);
}
double operator ^(const point &b)const { //叉乘
return x*b.y - y*b.x;
}
double operator *(const point &b)const { //点乘
return x*b.x + y*b.y;
}
double len() { //返回直角三角形的斜边长
return hypot(x, y);
}
}point;
typedef struct circle {//圆
double r;
point centre;
circle() { }
circle(point a,double b) {
centre = a;
r = b;
}
double len() {
return 2 * PI*r;
}
double area() {
return PI*r*r;
}
}circle;
circle org;
double ans, r;
int t, m;
double dist(point p1, point p2) { //返回平面上两点距离
return sqrt((p1 - p2)*(p1 - p2));
}
int CircleInterNum(circle a, circle b) {
double fh = fabs(a.r + b.r), fc = fabs(a.r - b.r), d = dist(a.centre, b.centre);
if (d>fh)
return -2; //外离,没有交点
if (d==fh)
return -1; //外切,一个交点
if (d > fc&&d < fh)
return 0; //相交,两个交点
if (d == fc)
return 1; //内切,一个交点
if (d < fc&&d>=0)
return 2; //内含,没有交点
} void CircleIntteLen(circle a, circle b) {
double d = dist(a.centre, b.centre);
double t = (d*d + a.r*a.r - b.r*b.r) / (2.0 * d);
double h = sqrt((a.r*a.r) - (t*t))*2;
double angle_a = 2*acos((a.r*a.r +d*d-b.r*b.r) / (2.0 * a.r*d)); //余弦公式计算圆心角,反三角计算出的是弧度
double angle_b = 2*acos((b.r*b.r +d*d-a.r*a.r) / (2.0 * b.r*d));
double la = angle_a*a.r;
double lb = angle_b*b.r;
ans += (lb-la);
}
int main(void) {
cin >> t;
while (t-- > 0) {
org.centre = point(0, 0);
cin >> m >> r;
org.r = r;
ans = org.len();
double x, y, rt;
for (int i = 0; i < m; i++) {
cin >> x >> y >> rt;
circle tmp = circle(point(x, y), rt);
if (CircleInterNum(org, tmp) == 0)
CircleIntteLen(org, tmp);
if (CircleInterNum(org, tmp) == 1)
ans += tmp.len();
}
printf("%.15f\n",ans);
}
return 0;
}

HDU 6354--Everything Has Changed(判断两圆关系+弧长计算)的更多相关文章

  1. c++ 判断两圆位置关系

    对于两圆的位置一般有五种关系: (1) 外离:两圆的半径之和小于两圆圆心距离 (2) 外切:两圆的半径之和等于两圆圆心距离 (3) 相交:两圆的半径之和大于两圆圆心距离,两圆圆心距离大于两圆半径之差 ...

  2. HDU 6354 Everything Has Changed(余弦定理)多校题解

    题意:源点处有个圆,然后给你m个圆(保证互不相交.内含),如果源点圆和这些原相交了,就剪掉相交的部分,问你最后周长(最外面那部分的长度). 思路:分类讨论,只有内切和相交会变化周长,然后乱搞就行了.题 ...

  3. LightOJ 1118--Incredible Molecules(两圆相交)

    1118 - Incredible Molecules      PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Lim ...

  4. 实验12:Problem D: 判断两个圆之间的关系

    Home Web Board ProblemSet Standing Status Statistics   Problem D: 判断两个圆之间的关系 Problem D: 判断两个圆之间的关系 T ...

  5. hdu 1147:Pick-up sticks(基本题,判断两线段相交)

    Pick-up sticks Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  6. hdu 1086:You can Solve a Geometry Problem too(计算几何,判断两线段相交,水题)

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  7. UVa 10674 (求两圆公切线) Tangents

    题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果 ...

  8. HDU 3264 Open-air shopping malls (计算几何-圆相交面积)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...

  9. 6354 Everything Has Changed

    Edward is a worker for Aluminum Cyclic Machinery. His work is operating mechanical arms to cut out d ...

随机推荐

  1. tomcat常用技巧

    1. 修改Tomcat的名称 适用场景: 在测试服务器资源有限或是在本机服务器部署多套应用系统时,由于要启动多个TOMCAT服务,且TOMCAT服务没有用名称去区分,会造成维护使用上存在一定晨读的不方 ...

  2. js图片上传并预览

    <form id="addpic" class="easyui-form" method="post" enctype="m ...

  3. Spring课程 Spring入门篇 4-6 Spring bean装配之基于java的容器注解说明--@ImportResource和@Value java与properties文件交互

    1 解析 1.1 这两个注解应用在什么地方 1.2 应用方式 1.3 xml方式实现取值 2 代码演练 2.1 @ImportResource和@Value代码演练 1 解析 1.1 这两个注解应用在 ...

  4. 前端框架——Bootstrap

    一.Bootstrap介绍 凡是使用过bootstrap的开发者,不外乎做这么两件事情:复制and粘贴. Bootstrap官方网址:http://www.bootcss.com Bootstrap, ...

  5. Android DataBinding实现地址三联动

    这篇文章主要是写关于Android实现地址三联动的功能,现在附上demo地址:https://github.com/qiuyueL/NewAddressDemo,里面会有详细的注释,以及控件的使用,其 ...

  6. Nodejs 如何制作命令行工具

    # 全局安装,安装报错是需要前面加上sudo $ sudo npm install -g xxxb # 输出帮助 $ xxxb -h Usage: xxxb 这里是我私人玩耍的命令哦![options ...

  7. vue 路由权限

    import Vue from 'vue' import Router from 'vue-router' import HelloWorld from '@/components/HelloWorl ...

  8. phonegap2.0+在xcode4.5上的搭建

    首先网上很多文章都是phonegap1.X的,可是自2.0后就没有相关的安装文件了,只有官网上写了怎么装 不过官网有时候打不开,可能是首页出了问题 但http://docs.phonegap.com这 ...

  9. Azure 8月众多新版本公布

    Azure 8月新发布:IoT 中心S3 版,Azure 热/冷存储层,DocumentDB,SQL Server Stretch Database, MySQL 5.7, Cloud Foundry ...

  10. 如何使用Putty登录安装在VirtualBox里的ubuntu

    我是在Windows操作系统里用VirtualBox安装了ubuntu操作系统. 在VirtualBox里操作ubuntu的终端不是很方便,比如我想在Windows里复制一些命令到ubuntu的终端执 ...