• 题目
  • 题意:首先给定一个以原点为圆心,R为半径的圆,之后在给m个圆,这些圆可能会和原来的圆有所交集,计算开始的圆剩余区域的周长,不包括内部周长。
  • 首先判定两圆关系,如果内含,直接加上圆的周长,如果相交,在计算对应弧长,其他情况都不用计算。在计算圆心角的时候,有个精度问题,只用本身半径算出来的弧度会不够,所有用上两个圆的半径。
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstdio>
  4. #include<cmath>
  5. using namespace std;
  6. const double PI = acos(-1.0);
  7. typedef struct point {
  8. double x;
  9. double y;
  10. point() {
  11. }
  12. point(double a, double b) {
  13. x = a;
  14. y = b;
  15. }
  16. point operator -(const point &b)const { //返回减去后的新点
  17. return point(x - b.x, y - b.y);
  18. }
  19. point operator +(const point &b)const { //返回加上后的新点
  20. return point(x + b.x, y + b.y);
  21. }
  22. //数乘计算
  23. point operator *(const double &k)const { //返回相乘后的新点
  24. return point(x * k, y * k);
  25. }
  26. point operator /(const double &k)const { //返回相除后的新点
  27. return point(x / k, y / k);
  28. }
  29. double operator ^(const point &b)const { //叉乘
  30. return x*b.y - y*b.x;
  31. }
  32. double operator *(const point &b)const { //点乘
  33. return x*b.x + y*b.y;
  34. }
  35. double len() { //返回直角三角形的斜边长
  36. return hypot(x, y);
  37. }
  38. }point;
  39. typedef struct circle {//圆
  40. double r;
  41. point centre;
  42. circle() {
  43. }
  44. circle(point a,double b) {
  45. centre = a;
  46. r = b;
  47. }
  48. double len() {
  49. return 2 * PI*r;
  50. }
  51. double area() {
  52. return PI*r*r;
  53. }
  54. }circle;
  55. circle org;
  56. double ans, r;
  57. int t, m;
  58. double dist(point p1, point p2) { //返回平面上两点距离
  59. return sqrt((p1 - p2)*(p1 - p2));
  60. }
  61. int CircleInterNum(circle a, circle b) {
  62. double fh = fabs(a.r + b.r), fc = fabs(a.r - b.r), d = dist(a.centre, b.centre);
  63. if (d>fh)
  64. return -2; //外离,没有交点
  65. if (d==fh)
  66. return -1; //外切,一个交点
  67. if (d > fc&&d < fh)
  68. return 0; //相交,两个交点
  69. if (d == fc)
  70. return 1; //内切,一个交点
  71. if (d < fc&&d>=0)
  72. return 2; //内含,没有交点
  73. }
  74. void CircleIntteLen(circle a, circle b) {
  75. double d = dist(a.centre, b.centre);
  76. double t = (d*d + a.r*a.r - b.r*b.r) / (2.0 * d);
  77. double h = sqrt((a.r*a.r) - (t*t))*2;
  78. double angle_a = 2*acos((a.r*a.r +d*d-b.r*b.r) / (2.0 * a.r*d)); //余弦公式计算圆心角,反三角计算出的是弧度
  79. double angle_b = 2*acos((b.r*b.r +d*d-a.r*a.r) / (2.0 * b.r*d));
  80. double la = angle_a*a.r;
  81. double lb = angle_b*b.r;
  82. ans += (lb-la);
  83. }
  84. int main(void) {
  85. cin >> t;
  86. while (t-- > 0) {
  87. org.centre = point(0, 0);
  88. cin >> m >> r;
  89. org.r = r;
  90. ans = org.len();
  91. double x, y, rt;
  92. for (int i = 0; i < m; i++) {
  93. cin >> x >> y >> rt;
  94. circle tmp = circle(point(x, y), rt);
  95. if (CircleInterNum(org, tmp) == 0)
  96. CircleIntteLen(org, tmp);
  97. if (CircleInterNum(org, tmp) == 1)
  98. ans += tmp.len();
  99. }
  100. printf("%.15f\n",ans);
  101. }
  102. return 0;
  103. }

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. flex布局的一些注意点

    现在来总结下自己在项目中用flex布局的一些注意点 1.ui图中的布局方式与justify-content的布局方法不一样 这是就要利用flex-grow的空dom来分开子容器来达到页面布局的效果 2 ...

  2. 集合之equals与hashCode方法

    一  equals equals方法是Object级的,默认对比两个对象的内存地址,很多类都重写了该方法,对比对象的实际内容,一般对比同一类对象相同属性的属性值是否相同. 二 hashCode 1.哈 ...

  3. Homebrew 的使用

    安装 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/ins ...

  4. Android Activity中状态保存机制

    在Activity中保存用户的当前操作状态,如输入框中的文本,一般情况下载按了home键后,重新进入文本框中的东西会丢下,所以我们要保存当前页面信息,如在写短信的时候接到一个电话,那么当你接电话的时候 ...

  5. GridCellChoiceEditor

    choice_editor = wx.grid.GridCellChoiceEditor(choices_list, True) grid.SetCellEditor(row, col, choice ...

  6. Hadoop ->> HIVE

    HIVE的由来: 最初由Facebook基于HDFS开发出来的一套数据仓库工具. HIVE可以干什么? HIVE可以将已经结构化的数据映射成一张表,然后可以使用HIVE语言像写T-SQL一样查询数据. ...

  7. windows默认共享的打开和关闭?

    windows默认共享的打开和关闭?   Windows启动时都会默认打开admin$ ipc$ 和每个盘符的共享,对于不必要的默认共享,一般都会把它取消掉,可当又需要打开此默认共享时,又该从哪里设置 ...

  8. centos下安装lnmp各个版本的几种方法

    首先我们用一种yum的方法安装,我们需要rpm源 默认的版本太低了,手动安装有一些麻烦,想采用Yum安装的可以使用下面的方案: 1.检查当前安装的PHP包 yum list installed | g ...

  9. 3.Zabbix 3.0 部署

    请查看我的有道云笔记: http://note.youdao.com/noteshare?id=0139b8d2833129740be82e36a94e4fca&sub=5931260FCC8 ...

  10. leetcode 322零钱兑换

    You are given coins of different denominations and a total amount of money amount. Write a function ...