Educational Codeforces Round 2 D.Area of Two Circles' Intersection(计算几何)
2016-01-18 15:55
477 查看
Educational Codeforces Round 2D:http://codeforces.com/contest/600/problem/D
D. Area of Two Circles' Intersection
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given two circles. Find the area of their intersection.
Input
The first line contains three integers x1, y1, r1 ( - 109 ≤ x1, y1 ≤ 109, 1 ≤ r1 ≤ 109)
— the position of the center and the radius of the first circle.
The second line contains three integers x2, y2, r2 ( - 109 ≤ x2, y2 ≤ 109, 1 ≤ r2 ≤ 109)
— the position of the center and the radius of the second circle.
Output
Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn't exceed10 - 6.
Sample test(s)
input
output
input
output
大致题意:求两个元的相交面积
原来做过hdu5120这道题,直接套用这题给的模版,结果一直wa
这组数据(0 1000000000 1 0 0 1000000000)错了,原来是模版有错误的地方
重新找了另一个模版
D. Area of Two Circles' Intersection
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given two circles. Find the area of their intersection.
Input
The first line contains three integers x1, y1, r1 ( - 109 ≤ x1, y1 ≤ 109, 1 ≤ r1 ≤ 109)
— the position of the center and the radius of the first circle.
The second line contains three integers x2, y2, r2 ( - 109 ≤ x2, y2 ≤ 109, 1 ≤ r2 ≤ 109)
— the position of the center and the radius of the second circle.
Output
Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn't exceed10 - 6.
Sample test(s)
input
0 0 4 6 0 4
output
7.25298806364175601379
input
0 0 5 11 0 5
output
0.00000000000000000000
大致题意:求两个元的相交面积
原来做过hdu5120这道题,直接套用这题给的模版,结果一直wa
这组数据(0 1000000000 1 0 0 1000000000)错了,原来是模版有错误的地方
重新找了另一个模版
#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> using namespace std; typedef long double ld; typedef long long ll; ld x[2],y[2],r[2]; const ld pi = acosl(-1); inline ld sqr(ld x) { return x*x; } inline ll sqrl(ll x) { return x*x; } inline ld fcos(ld a, ld b, ld c) { return acosl((a*a+b*b-c*c)/(2*a*b)); } inline ld cut(ld ang, ld r) { ld s1 = ang*r*r; ld s2 = sinl(ang)*cosl(ang)*r*r; return s1 - s2; } double solve() { if(r[0] > r[1]) { swap(r[0],r[1]); swap(x[0],x[1]); swap(y[0],y[1]); } ll dx = x[0]-x[1], dy = y[0]-y[1]; ll ds = sqrl(dx)+sqrl(dy); if(ds >= sqrl(r[0]+r[1])) return 0; ld d = sqrtl(ds); if(d+r[0] <= r[1]) return sqr(r[0])*pi; ld ang[2]; ang[0] = fcos(d,r[0],r[1]); ang[1] = fcos(d,r[1],r[0]); return cut(ang[0],r[0]) + cut(ang[1],r[1]); } int main() { while(cin>>x[0]>>y[0]>>r[0]>>x[1]>>y[1]>>r[1]) { printf("%.6lf\n",solve()); } return 0; }
相关文章推荐
- LitePal学习笔记
- maven deploy到私库
- VC引入lib库并解决连接错误unresolved external symbol "__declspec(dllimport) const DllClass::`vftable'" (__imp_?
- android打开前置摄像头和后置摄像头
- 今后需要养成的习惯
- 使用 symbolicatecrash 解析崩溃堆栈
- redis中各种数据类型对应的jedis操作命令
- 多线程编程(四)--线程同步
- 2016/1/18
- 数据库---查询所用的关键字汇总
- 计算机语言基础
- Struts2之action接收请求参数
- 操作系统与网络实现 之十四
- 数据库---高级查询
- Ubuntu安装libgtk-x11-2.0
- eCAP
- Android Gradle Release Version 2.4 增加多进程并行编译,经测试可以提升编译速度20% 到 40%
- oracle创建表空间,用户步骤
- Spring data 接口之 自定义Repository 接口
- zpar使用方法之Chinese Word Segmentation