Intersection(计算几何)
Intersection
Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 3018 Accepted Submission(s): 1135
Problem Description
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The following figures are some famous examples you may know.
A ring is a 2-D figure bounded by two circles sharing the common center. The radius for these circles are denoted by r and R (r < R). For more details, refer to the gray part in the illustration below.
Matt just designed a new logo consisting of two rings with the same size in the 2-D plane. For his interests, Matt would like to know the area of the intersection of these two rings.
Input
The first line contains only one integer T (T ≤ 105), which indicates the number of test cases. For each test case, the first line contains two integers r, R (0 ≤ r < R ≤ 10).
Each of the following two lines contains two integers xi, yi (0 ≤ xi, yi ≤ 20) indicating the coordinates of the center of each ring.
Output
For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y is the area of intersection rounded to 6 decimal places.
Sample Input
Sample Output
Source
2014ACM/ICPC亚洲区北京站-重现赛(感谢北师和上交)
//题意:问两个同样大的圆环相交的面积是多大
画图后,可以发现,用容斥定理很简单,area = 两个大圆的相交面积 - 2 * 大圆和小圆相交面积 + 两个小圆相交面积
求面积要用余弦定理,然后就简单了
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define LL long long
#define PI acos(-1.0)
#define lowbit(x) (x&(-x))
#define INF 0x7f7f7f7f // 21 E
#define MEM 0x7f // memset 都变为 INF
#define MOD 4999 // 模
#define eps 1e-9 // 精度
#define MX 1000005 // 数据范围 int read() { //输入外挂
int res = , flag = ;
char ch;
if((ch = getchar()) == '-') flag = ;
else if(ch >= '' && ch <= '') res = ch - '';
while((ch = getchar()) >= '' && ch <= '') res = res * + (ch - '');
return flag ? -res : res;
}
// code... ... double area(double x1,double y1,double r1,double x2,double y2,double r2)
{
double d=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(d>=(r1+r2)*(r1+r2)) return ;
if(d<=(r1-r2)*(r1-r2)) return r1<r2 ? PI*r1*r1 : PI*r2*r2;
d=sqrt(d);
double a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d));
double a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d));
double s1=a1*r1*r1; //扇形s1
double s2=a2*r2*r2;
double sinx = sqrt(-cos(a1)*cos(a1));
double t = sinx * d * r1; //三角形
return s1+s2-t;
} int main()
{
int T;
cin>>T;
for (int cnt=;cnt<=T;cnt++)
{
double x1,y1,x2,y2,r1,r2;
scanf("%lf%lf",&r1,&r2);
scanf("%lf%lf",&x1,&y1);
scanf("%lf%lf",&x2,&y2);
double ans = area(x1,y1,r2,x2,y2,r2);
ans -= *area(x1,y1,r1,x2,y2,r2);
ans += area(x1,y1,r1,x2,y2,r1);
printf("Case #%d: %.6f\n",cnt,ans);
}
}
Intersection(计算几何)的更多相关文章
- POJ 1410 Intersection (计算几何)
题目链接:POJ 1410 Description You are to write a program that has to decide whether a given line segment ...
- codeforces D. Area of Two Circles' Intersection 计算几何
D. Area of Two Circles' Intersection time limit per test 2 seconds memory limit per test 256 megabyt ...
- hdu-5120 Intersection(计算几何)
题目链接: Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Ot ...
- POJ1410 Intersection 计算几何
题目大意:给出一个线段的两端,和矩形两端(不一定是左上和右下),问线段是否与矩形相交(若线段在矩形内也算相交).这题蒸鹅心-- 题目思路:判断所有情况:线段是否在矩形内,线段内一点是否在矩形内,线段是 ...
- 计算几何(容斥原理,圆交):HDU 5120 Intersection
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The followin ...
- Gym 100952J&&2015 HIAST Collegiate Programming Contest J. Polygons Intersection【计算几何求解两个凸多边形的相交面积板子题】
J. Polygons Intersection time limit per test:2 seconds memory limit per test:64 megabytes input:stan ...
- HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...
- POJ 1410 Intersection(计算几何)
题目大意:题目意思很简单,就是说有一个矩阵是实心的,给出一条线段,问线段和矩阵是否相交解题思路:用到了线段与线段是否交叉,然后再判断线段是否在矩阵里面,这里要注意的是,他给出的矩阵的坐标明显不是左上和 ...
- HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4063 Description You are playing a flying game. In th ...
随机推荐
- 数据库学习--wildfly配置postgreSQL数据源
前言 实验室最近在做一个物品管理系统的小项目,其中涉及到postgreSQL的使用,刚开始部署到wildfly服务器上时遇到了若干问题,终于在导师的讲解下大体上明白了 ,特此记录分享学习一下. 配置数 ...
- python获取输入参数
python获取输入参数 学习了:https://www.cnblogs.com/angelatian/p/5832448.html import sys模块: len(sys.argv)参数个数 s ...
- 【HTML 元素】嵌入图像
img元素允许我们在HTML文档里嵌入图像. 要嵌入一张图像需要使用src和alt属性,代码如下: <img src="../img/example/img-map.jpg" ...
- hbuilder - wap to app
官方文档: http://www.dcloud.io/wap2app.html 新建Wap2App,示例网址:www.baidu.com 随后,我们可以在 最后,我们可以 打包完成以后,下载即可
- 【Shell】建立一个脚本统计当前登录用户数
who命令 who命令是显示目前登陆系统的用户信息,执行who命令可以得知目前哪些用户登入系统,单独执行who命令会列出登入账号,使用的终端机,登入的时间以及从何处登入或正在使用哪个显示器. 统计用户 ...
- linux与开发板串口通信
研究了一天的linux串口,结果改了树莓派的系统配置文件config.txt给改了导致系统崩溃....其实我感觉网上的大多数方法都是不符合新版本树莓派的,网上的方法是通过修改系统配置文件后安装mini ...
- C# 反编译工具
justdecompile http://down.51cto.com/data/2067031 ILSpy http://www.fishlee.net/soft/ilspy_chs/
- asp.net core mvc视频A:笔记3-6.视图数据共享之session/cache
第一部分:Session讲解 会话级别的,怎么区分呢?以浏览器为单位,比如IE,搜狗等等,都算一个单独的会话 修改3.5项目 控制器代码 前端显示 startup.cs中配置并启用Session 运行 ...
- Hadoop 中的 ArrayWritable
虽然ArrayWritable不是接口,但貌似必须要子类去extends ArrayWritable,不能直接用ArrayWriable 否则会报下面的错误?(不是很确定) java.lang.Exc ...
- Spring Security三种认证
Spring Security: 1.用户名+密码认证 2.手机号+短信认证 Spring Social: 1.第三方认证, QQ登录等 Spring Security OAuth: 1.把认证之后的 ...