HDU 6354--Everything Has Changed(判断两圆关系+弧长计算)
- 题目
- 题意:首先给定一个以原点为圆心,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(判断两圆关系+弧长计算)的更多相关文章
- c++ 判断两圆位置关系
对于两圆的位置一般有五种关系: (1) 外离:两圆的半径之和小于两圆圆心距离 (2) 外切:两圆的半径之和等于两圆圆心距离 (3) 相交:两圆的半径之和大于两圆圆心距离,两圆圆心距离大于两圆半径之差 ...
- HDU 6354 Everything Has Changed(余弦定理)多校题解
题意:源点处有个圆,然后给你m个圆(保证互不相交.内含),如果源点圆和这些原相交了,就剪掉相交的部分,问你最后周长(最外面那部分的长度). 思路:分类讨论,只有内切和相交会变化周长,然后乱搞就行了.题 ...
- LightOJ 1118--Incredible Molecules(两圆相交)
1118 - Incredible Molecules PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Lim ...
- 实验12:Problem D: 判断两个圆之间的关系
Home Web Board ProblemSet Standing Status Statistics Problem D: 判断两个圆之间的关系 Problem D: 判断两个圆之间的关系 T ...
- hdu 1147:Pick-up sticks(基本题,判断两线段相交)
Pick-up sticks Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 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 ...
- UVa 10674 (求两圆公切线) Tangents
题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果 ...
- HDU 3264 Open-air shopping malls (计算几何-圆相交面积)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...
- 6354 Everything Has Changed
Edward is a worker for Aluminum Cyclic Machinery. His work is operating mechanical arms to cut out d ...
随机推荐
- flex布局的一些注意点
现在来总结下自己在项目中用flex布局的一些注意点 1.ui图中的布局方式与justify-content的布局方法不一样 这是就要利用flex-grow的空dom来分开子容器来达到页面布局的效果 2 ...
- 集合之equals与hashCode方法
一 equals equals方法是Object级的,默认对比两个对象的内存地址,很多类都重写了该方法,对比对象的实际内容,一般对比同一类对象相同属性的属性值是否相同. 二 hashCode 1.哈 ...
- Homebrew 的使用
安装 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/ins ...
- Android Activity中状态保存机制
在Activity中保存用户的当前操作状态,如输入框中的文本,一般情况下载按了home键后,重新进入文本框中的东西会丢下,所以我们要保存当前页面信息,如在写短信的时候接到一个电话,那么当你接电话的时候 ...
- GridCellChoiceEditor
choice_editor = wx.grid.GridCellChoiceEditor(choices_list, True) grid.SetCellEditor(row, col, choice ...
- Hadoop ->> HIVE
HIVE的由来: 最初由Facebook基于HDFS开发出来的一套数据仓库工具. HIVE可以干什么? HIVE可以将已经结构化的数据映射成一张表,然后可以使用HIVE语言像写T-SQL一样查询数据. ...
- windows默认共享的打开和关闭?
windows默认共享的打开和关闭? Windows启动时都会默认打开admin$ ipc$ 和每个盘符的共享,对于不必要的默认共享,一般都会把它取消掉,可当又需要打开此默认共享时,又该从哪里设置 ...
- centos下安装lnmp各个版本的几种方法
首先我们用一种yum的方法安装,我们需要rpm源 默认的版本太低了,手动安装有一些麻烦,想采用Yum安装的可以使用下面的方案: 1.检查当前安装的PHP包 yum list installed | g ...
- 3.Zabbix 3.0 部署
请查看我的有道云笔记: http://note.youdao.com/noteshare?id=0139b8d2833129740be82e36a94e4fca&sub=5931260FCC8 ...
- leetcode 322零钱兑换
You are given coins of different denominations and a total amount of money amount. Write a function ...