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 ...
随机推荐
- Hunt the Wumpus第二个版本---多怪兽,多洞穴,洞穴间双向互通
其中,将洞穴连起来的算法要好好体会. 学习构建临时变量列表,确认循环用FOR,非确定循环用 WHILE,并定好退出条件. from random import choice cave_numbers ...
- BZOJ 2732 射箭
http://www.lydsy.com/JudgeOnline/problem.php?id=2732 题意:给你n个靶子,让你求是否有一个经过原点的抛物线经过最多的前k个靶子,求出最大的k 思路: ...
- XJOI网上同步训练DAY5 T3
就是对于一个数,我们去考虑把t*****减到(t-1)9999*的代价. #include<cstdio> #include<cmath> #include<algori ...
- 各类XML parser的比较
基于以上的比较 再为公司的项目选择解析器的时候,我选择Xerces.准备把Qt自带的XML库给去掉. references: http://stackoverflow.com/questions/17 ...
- Cmake find_package()相关
也就是find_package可以帮助直接找到库的头文件和库文件(.lib,dll .etc) References: http://blog.csdn.net/dbzhang800/article/ ...
- Linux磁盘及文件系统管理 2---- 使用fdisk进行磁盘管理
1 FDISK分区工具 1 fsidk是来自IBM的分区工具,支持绝大多数的操作系统,几乎所有的Linux都装有fdisk 2 fdisk是一个支持MBR的分区工具,如果要使用GPT的话我们无法使用f ...
- centerOS安装rkhunter
rkhunter是专业检测系统是否感染rootkit的一个工具: rkhunter-1.4.2.tar.gz 解压后直接安装: #./installer.sh --layout defualt --i ...
- 传智播客 Html基础知识学习笔记
HTML基础 <p></p>标志对用来创建一个段落,,<p>标志还可以使用align属性, 它用来说明对齐方式 语法是:<p align="&quo ...
- js获取url传递参数(转的,原作不详)
这里是一个获取URL带QUESTRING参数的JAVASCRIPT客户端解决方案,相当于asp的request.querystring,PHP的$_GET 函数: <Script languag ...
- (转)iOS Wow体验 - 第六章 - 交互模型与创新的产品概念(1)
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第六章译文精选,其余章节将陆续放出.上一篇:Wow ...