题目链接:http://lightoj.com/volume_showproblem.php?problem=1118

给你两个圆的半径和圆心,求交集的面积;

就是简单数学题,但是要注意acos得到的都是小于180度的角,所以这里要注意一下,不要求整个角,求一半的大小;这点让我错的惨不忍睹;

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h> using namespace std; #define met(a, b) memset(a, b, sizeof(a))
#define N 1053
#define INF 0x3f3f3f3f
#define PI 4*atan(1)
const int MOD = ; typedef long long LL; int main()
{
int T, t = ;
scanf("%d", &T);
while(T--)
{
double r1, r2, x1, x2, y1, y2; scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &r1, &x2, &y2, &r2); double d = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); if( d >= r1+r2 )///相离或相切
{
printf("Case %d: %.6f\n", t++, 0.0);
continue;
}
if(d <= fabs(r1-r2))///内含;
{
printf("Case %d: %.6f\n", t++, PI*min(r1, r2)*min(r1, r2));
continue;
} double a = acos((r1*r1+r2*r2-d*d)/(*r1*r2));
double s = sin(a)*r1*r2;///四边形面积
double b = acos((r1*r1+d*d-r2*r2)/(*r1*d));
double s1 = b * r1 * r1;///r1这边的扇形面积;
double c = acos((r2*r2+d*d-r1*r1)/(*r2*d));
double s2 = c * r2 * r2;///r2这边的扇形面积;
double ans = s1 + s2 - s; printf("Case %d: %.7f\n", t++, ans);
}
return ;
}
/*
Input:
5
0 0 1 10 10 1
0 0 10 0 0 5
-862 823 894 -667 402 663
548 518 145 119 828 620
777 499 712 479 314 967 Output:
Case 1: 0.0
Case 2: 78.5398163397
Case 3: 1139058.0639436883
Case 4: 56622.85922574766
Case 5: 1513681.0685423985
*/

LightOj 1118 - Incredible Molecules(两圆的交集面积)的更多相关文章

  1. LightOJ 1118 - Incredible Molecules (两圆面积交)

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

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

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

  3. POJ 2546 &amp; ZOJ 1597 Circular Area(求两圆相交的面积 模板)

    题目链接: POJ:http://poj.org/problem? id=2546 ZOJ:problemId=597" target="_blank">http: ...

  4. 求两圆相交部分面积(C++)

    已知两圆圆心坐标和半径,求相交部分面积: #include <iostream> using namespace std; #include<cmath> #include&l ...

  5. codeforce gym/100495/problem/K—Wolf and sheep 两圆求相交面积 与 gym/100495/problem/E—Simple sequence思路简述

    之前几乎没写过什么这种几何的计算题.在众多大佬的博客下终于记起来了当时的公式.嘚赶快补计算几何和概率论的坑了... 这题的要求,在对两圆相交的板子略做修改后,很容易实现.这里直接给出代码.重点的部分有 ...

  6. 两圆相交求面积 hdu5120

    转载 两圆相交分如下集中情况:相离.相切.相交.包含. 设两圆圆心分别是O1和O2,半径分别是r1和r2,设d为两圆心距离.又因为两圆有大有小,我们设较小的圆是O1. 相离相切的面积为零,代码如下: ...

  7. hdu 5120 (求两圆相交的面积

    题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #in ...

  8. hdu5858 Hard problem(求两圆相交面积)

    题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  9. HDU 6354--Everything Has Changed(判断两圆关系+弧长计算)

    题目 题意:首先给定一个以原点为圆心,R为半径的圆,之后在给m个圆,这些圆可能会和原来的圆有所交集,计算开始的圆剩余区域的周长,不包括内部周长. 首先判定两圆关系,如果内含,直接加上圆的周长,如果相交 ...

随机推荐

  1. 3dmax导出模型使用相对路径读取纹理贴图

    Shift+T快捷键打开“资源跟踪”窗口

  2. [Python] Python 之 function, unbound method 和 bound method

    首先看一下以下示例.(Python 2.7) #!/usr/bin/env python # -*- coding: utf-8 -*- class C(object): def foo(self): ...

  3. MQTT-C-UDP_PUB

    /** ****************************************************************************** * @file    apdu.c ...

  4. ISD9160学习笔记04_ISD9160音频编码代码分析

    前言 录音例程涉及了录音和播放两大块内容,上篇笔记说了播放,这篇就来说说录音这块,也就是音频编码这部分功能. 上篇笔记中的这段话太装逼了,我决定再复制下,嘿嘿. “我的锤子便签中有上个月记下的一句话, ...

  5. ATM技术基本原理

    1 术语.定义和缩略语 1.1 术语.定义 术语/定义 说    明 ATM层 位于B-ISDN/ATM网络协议参考模型的第二层,完成交换.路由选择和信元复用功能.ATM层的基本处理单位是信元. AA ...

  6. 【node.js】】MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。

    错误原因:缺少windows构建插件 解决方法: # (全局安装windows构建工具) npm install --global --production windows-build-tools

  7. 重建索引:ALTER INDEX..REBUILD ONLINE vs ALTER INDEX..REBUILD

    什么时候需要重建索引 1. 删除的空间没有重用,导致 索引出现碎片 2. 删除大量的表数据后,空间没有重用,导致 索引"虚高" 3.索引的 clustering_facto 和表不 ...

  8. Elasticsearch学习之head插件安装

    通过elasticseach自带的plugin命令 elasticsearch/bin/plugin -install mobz/elasticsearch-head 如下图:  2. zip包安装 ...

  9. LeetCode 46 Permutations(全排列问题)

    题目链接:https://leetcode.com/problems/permutations/?tab=Description   Problem:给出一个数组(数组中的元素均不相同),求出这个数组 ...

  10. sencha touch routes(路由) 传递中文参数

    使用路由的时候可以传递参数 如下: index.html#eaterylist/335/61/61/61/B/商户名称 其中6个参数依次是:商户编号/公众账号/微信号/校验号/服务类型/商户名称 因为 ...