POJ 3675 Telescope
题意:给定一个不自交的多边形,要求和圆心在原点的圆的面积交.
思路:同POJ2986,是加强版
代码:
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
struct Point{
double x,y;
Point(){}
Point(double x0,double y0):x(x0),y(y0){}
}p[],a[],O;
struct Line{
Point s,e;
Line(){}
Line(Point s0,Point e0):s(s0),e(e0){}
};
int n;
double R;
const double eps=1e-;
const double Pi=acos(-);
double sgn(double x){
if (x>eps) return 1.0;
if (x<-eps) return -1.0;
return ;
}
Point operator *(Point p1,double x){
return Point(p1.x*x,p1.y*x);
}
Point operator /(Point p1,double x){
return Point(p1.x/x,p1.y/x);
}
double operator /(Point p1,Point p2){
return p1.x*p2.x+p1.y*p2.y;
}
double operator *(Point p1,Point p2){
return p1.x*p2.y-p1.y*p2.x;
}
Point operator +(Point p1,Point p2){
return Point(p1.x+p2.x,p1.y+p2.y);
}
Point operator -(Point p1,Point p2){
return Point(p1.x-p2.x,p1.y-p2.y);
}
double dis(Point p1){
return sqrt(p1.x*p1.x+p1.y*p1.y);
}
double dis(Point p1,Point p2){
return dis(Point(p1.x-p2.x,p1.y-p2.y));
}
double sqr(double x){
return x*x;
}
double dist_line(Line p){
double A,B,C,dist;
A=p.s.y-p.e.y;
B=p.s.x-p.e.x;
C=p.s.x*p.e.y-p.s.y*p.e.x;
dist=fabs(C)/sqrt(sqr(A)+sqr(B));
return dist;
}
double get_cos(double a,double b,double c){
return (b*b+c*c-a*a)/(*b*c);
}
double get_angle(Point p1,Point p2){
if (!sgn(dis(p1))||!sgn(dis(p2))) return 0.0;
double A,B,C;
A=dis(p1);
B=dis(p2);
C=dis(p1,p2);
if (C<=eps) return 0.0;
return acos(get_cos(C,A,B));
}
Point get_point(Point p){
double T=sqr(p.x)+sqr(p.y);
return Point(sgn(p.x)*sqrt(sqr(p.x)/T),sgn(p.y)*sqrt(sqr(p.y)/T));
}
double S(Point p1,Point p2,Point p3){
return fabs((p2-p1)*(p3-p1))/;
}
double work(Point p1,Point p2){
double f=sgn(p1*p2),res=;
if (!sgn(f)||!sgn(dis(p1))||!sgn(dis(p2))) return 0.0;
double l=dist_line(Line(p1,p2));
double a=dis(p1);
double b=dis(p2);
double c=dis(p1,p2);
if (a<=R&&b<=R){
return fabs(p1*p2)/2.0*f;
}
if (a>=R&&b>=R&&l>=R){
double ang=get_angle(p1,p2);
return fabs((ang/(2.0))*(R*R))*f;
}
if (a>=R&&b>=R&&l<=R&&(get_cos(a,b,c)<=||get_cos(b,a,c)<=)){
double ang=get_angle(p1,p2);
return fabs((ang/(2.0))*(R*R))*f;
}
if (a>=R&&b>=R&&l<=R&&(get_cos(a,b,c)>&&get_cos(b,a,c)>)){
double dist=dist_line(Line(p1,p2));
double len=sqrt(sqr(R)-sqr(dist))*2.0;
double ang1=get_angle(p1,p2);
double cos2=get_cos(len,R,R);
res+=fabs(len*dist/2.0);
double ang2=ang1-acos(cos2);
res+=fabs((ang2/())*(R*R));
return res*f;
}
if ((a>=R&&b<R)||(a<R&&b>=R)){
if (b>a) std::swap(a,b),std::swap(p1,p2);
double T=sqr(p1.x-p2.x)+sqr(p1.y-p2.y);
Point u=Point(sgn(p1.x-p2.x)*sqrt(sqr(p1.x-p2.x)/T),sgn(p1.y-p2.y)*sqrt(sqr(p1.y-p2.y)/T));
double dist=dist_line(Line(p1,p2));
double len=sqrt(R*R-dist*dist);
double len2=sqrt(sqr(dis(p2))-sqr(dist));
if (fabs(dis(p2+u*len2)-dist)<=eps) len+=len2;
else len-=len2;
Point p=p2+u*len;
res+=S(O,p2,p);
double ang=get_angle(p1,p);
res+=fabs((ang/2.0)*R*R);
return res*f;
}
return ;
}
int main(){
O=Point(,);
while (scanf("%lf",&R)!=EOF){
scanf("%d",&n);
for (int i=;i<=n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
p[n+]=p[];
double ans=;
for (int i=;i<=n;i++)
ans+=work(p[i],p[i+]);
ans=fabs(ans);
printf("%.2f\n",ans);
}
}
POJ 3675 Telescope的更多相关文章
- poj 3675 Telescope (圆与多边形面积交)
3675 -- Telescope 再来一题.这题的代码还是继续完全不看模板重写的. 题意不解释了,反正就是一个单纯的圆与多边形的交面积. 这题的精度有点搞笑.我用比较高的精度来统计面积,居然wa了. ...
- POJ 3675 Telescope(简单多边形和圆的面积交)
Description Updog is watching a plane object with a telescope. The field of vision in the telescope ...
- POJ 3675 Telescope 简单多边形和圆的面积交
这道题得控制好精度,不然会贡献WA QAQ 还是那个规则: int sgn(double x){ if(x > eps) return 1; else if(x < - eps) ret ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- 穷举(四):POJ上的两道穷举例题POJ 1411和POJ 1753
下面给出两道POJ上的问题,看如何用穷举法解决. [例9]Calling Extraterrestrial Intelligence Again(POJ 1411) Description A mes ...
- POJ 3130 How I Mathematician Wonder What You Are! (半平面交)
题目链接:POJ 3130 Problem Description After counting so many stars in the sky in his childhood, Isaac, n ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
随机推荐
- Android获取当前时间与星期几
public class DataString { private static String mYear; private static String mMonth; private static ...
- pywin32 安装错误 ImportError: DLL load failed: 不是有效的 Win32 应用程序
pywin32 安装错误 ImportError: DLL load failed: 不是有效的 Win32 应用程序. 发现是因为没有制定Pywin32的dll所致,我们在用Pywin32开发时, ...
- hdu1573:数论,线性同余方程组
题目大意: 给定一个N ,m 找到小于N的 对于i=1....m,满足 x mod ai=bi 的 x 的数量. 分析 先求出 同余方程组 的最小解x0,然后 每增加lcm(a1...,am)都 ...
- 【剑指offer】面试题41:和为 s 的两个数字 VS 和为 s 的连续正数序列
题目: 输出所有和为S的连续正数序列.序列内按照从小至大的顺序,序列间按照开始数字从小到大的顺序 思路: small代表序列最小数字,large代表序列最大数字.初始化small为1,large为2. ...
- Fence Repair (POJ 3253)
农夫约翰为了修理栅栏,要将一块很长的木板切割成N块.准备切成的木板长度为L1.L2.L3...LN,未切割前的木板长度恰好为切割后木板长度的总和.每次切断木板时,需要的开销为这块木板的长度.例如长度为 ...
- phpcms:四、尾部包含
四.尾部包含1.包含尾部文件:{template "content","footer"}2.栏目列表调用(关于我们| 联系方式| 版权声明| 招聘信息|):{p ...
- css中的7中属性选择器
在CSS的选择符中有七个属性选择符.它们分别是: 1.E[att] 选择具有att属性的E元素. 2.E[att="val"] 选择具有att属性且属性值等于val的E元素. 3. ...
- c语言学习之结构篇代码演示样例-输入n个同学的姓名,数学英语成绩,依照平均分从低到高排序并输出
#include<stdio.h> void main(){ const int count = 5;//定义数量 struct student{ char name[80]; float ...
- Dynamics CRM 2016 使用Plug-in Trace Log调试插件
1.写插件 首先,让我们写一个简单的插件来测试新插件跟踪日志功能.请注意,在下面的示例代码中,我们增加ITracingService的一个实例,以及记录有关插件的执行信息记录的一些键值: 2.注册插件 ...
- 图像重采样(CPU和GPU)
1 前言 之前在写影像融合算法的时候,免不了要实现将多光谱影像重采样到全色大小.当时为了不影响融合算法整体开发进度,其中重采样功能用的是GDAL开源库中的Warp接口实现的. 后来发现GDAL War ...