POJ3675 Telescope 圆和多边形的交
用三角剖分可以轻松搞定,数据也小 随便AC。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const double eps=1e-10,PI=acos(-1.0); int cmp(double k)
{
return k<-eps ? -1:k>eps ? 1:0;
} const double pi=acos(-1.0); inline double sqr(double x)
{
return x*x;
} struct point
{
double x,y;
point (){}
point (double a,double b):x(a),y(b){}
bool input()
{
return scanf("%lf%lf",&x,&y)!=EOF;
}
friend point operator +(const point &a,const point &b)
{
return point(a.x+b.x,a.y+b.y);
}
friend point operator -(const point &a,const point &b)
{
return point(a.x-b.x,a.y-b.y);
}
friend bool operator ==(const point &a,const point &b)
{
return cmp(a.x-b.x)==0&&cmp(a.y-b.y)==0;
}
friend point operator *(const point &a,const double &b)
{
return point(a.x*b,a.y*b);
}
friend point operator*(const double &a,const point &b)
{
return point(a*b.x,a*b.y);
}
friend point operator /(const point &a,const double &b)
{
return point(a.x/b,a.y/b);
}
double norm()
{
return sqr(x)+sqr(y);
}
}; double mysqrt(double x)
{
return sqrt(x);
}
double dot(const point &a,const point &b)
{
return a.x*b.x+a.y*b.y;
}
double cross(const point &a,const point &b)
{
return a.x*b.y-a.y*b.x;
}
double abs(const point &o)
{
return sqrt(dot(o,o));
}
void circle_cross_line(point a,point b,point o,double r,point ret[],int &num)
{
double x0=o.x,y0=o.y;
double x1=a.x,y1=a.y;
double x2=b.x,y2=b.y;
double dx=x2-x1,dy=y2-y1;
double A=dx*dx+dy*dy;
double B=2*dx*(x1-x0)+2*dy*(y1-y0);
double C=sqr(x1-x0)+sqr(y1-y0)-sqr(r);
double delta=B*B-4*A*C;
num=0;
if(cmp(delta)>=0)
{
double t1=(-B-mysqrt(delta))/(2*A);
double t2=(-B+mysqrt(delta))/(2*A);
if(cmp(t1-1)<=0&&cmp(t1)>=0)
{
ret[num++]=point(x1+t1*dx,y1+t1*dy);
}
if(cmp(t2-1)<=0&&cmp(t2)>=0)
{
ret[num++]=point(x1+t2*dx,y1+t2*dy);
}
}
} point crosspt(const point &a,const point &b,const point &p,const point &q)
{
double a1=cross(b-a,p-a);
double a2=cross(b-a,q-a);
return (p*a2-q*a1)/(a2-a1);
} double sector_area(const point &a,const point &b,const double r)
{
double theta=atan2(a.y,a.x)-atan2(b.y,b.x);
while(cmp(theta)<=0)theta+=2*PI;
while(cmp(theta-2*PI)>0)theta-=2*PI;
theta=min(theta,2*PI-theta);
return r*r*theta/2.;
} double calc_c(const point &a,const point &b,const double r)
{
point p[2];
int num=0;
bool ina=cmp(abs(a)-r)<0;
bool inb=cmp(abs(b)-r)<0;
if(ina)
{
if(inb)return fabs(cross(a,b))/2.;
else
{
circle_cross_line(a,b,point(0,0),r,p,num);
return fabs(sector_area(b,p[0],r))+fabs(cross(a,p[0]))/2.;
}
}
else
{
if(inb)
{
circle_cross_line(a,b,point(0,0),r,p,num);
return fabs(sector_area(p[0],a,r))+fabs(cross(p[0],b))/2.;
}
else
{
circle_cross_line(a,b,point(0,0),r,p,num);
if(num==2)
{
return fabs(sector_area(a,p[0],r))+fabs(sector_area(p[1],b,r))+fabs(cross(p[0],p[1]))/2.; }else
{
return fabs(sector_area(a,b,r));
}
}
}
} double area(int n,point res[],double r)
{
double ret=0.;
for(int i=0;i<n;i++)
{
int sgn=cmp(cross(res[i],res[(i+1)%n]));
if(sgn!=0)
{
ret+=sgn*calc_c(res[i],res[(i+1)%n],r);
}
}
return ret;
}
point pp[100];
int main()
{freopen("t.txt","r",stdin);
double r;
int n;
while(scanf("%lf",&r)!=EOF)
{ scanf("%d",&n);
for(int i=0;i<n;i++)
pp[i].input();
pp[n]=pp[0];
printf("%.2f\n",fabs(area(n,pp,r))+eps);
}
return 0;
}
POJ3675 Telescope 圆和多边形的交的更多相关文章
- poj 3675 Telescope (圆与多边形面积交)
3675 -- Telescope 再来一题.这题的代码还是继续完全不看模板重写的. 题意不解释了,反正就是一个单纯的圆与多边形的交面积. 这题的精度有点搞笑.我用比较高的精度来统计面积,居然wa了. ...
- Gym - 101208J 2013 ACM-ICPC World Finals J.Pollution Solution 圆与多边形面积交
题面 题意:给你一个半圆,和另一个多边形(可凹可凸),求面积交 题解:直接上板子,因为其实这个多边形不会穿过这个半圆,所以他和圆的交也就是和半圆的交 打的时候队友说凹的不行,不是板题,后面想想,圆与多 ...
- HDU - 3982:Harry Potter and J.K.Rowling(半平面交+圆与多边形求交)(WA ing)
pro:给定一枚蛋糕,蛋糕上某个位置有个草莓,寿星在上面切了N刀,最后寿星会吃含有草莓的那一块蛋糕,问他的蛋糕占总蛋糕的面积比. sol:显然需要半平面交求含有蛋糕的那一块,然后有圆弧,不太方便求交. ...
- LA 7072 Signal Interference 计算几何 圆与多边形的交
题意: 给出一个\(n\)个点的简单多边形,和两个点\(A, B\)还有一个常数\(k(0.2 \leq k < 0.8)\). 点\(P\)满足\(\left | PB \right | \l ...
- HDU - 2892:area (圆与多边形交 求面积)
pro:飞行员去轰炸一个小岛,给出炸弹落地点的位置信息,以及轰炸半径:按顺时针或者逆时针给出小岛的边界点. 求被轰炸的小岛面积. sol:即是求圆和多边形的面积交. (只会套板子的我改头换面,先理解然 ...
- Gym-101158J Cover the Polygon with Your Disk 计算几何 求动圆与多边形最大面积交
题面 题意:给出小于10个点形成的凸多边形 和一个半径为r 可以移动的圆 求圆心在何处的面积交最大,面积为多少 题解:三分套三分求出圆心位置,再用圆与多边形面积求交 #include<bits/ ...
- hdu 3982 Harry Potter and J.K.Rowling (半平面交 + 圆与多边形交)
Problem - 3982 题意就是给出一个圆心在原点半径为R的圆形蛋糕,上面有一个cherry,对蛋糕切若干刀,最后要求求出有cherry的那块的面积占整个蛋糕的多少. 做法显而易见,就是一个半平 ...
- 牛客网暑期ACM多校训练营(第三场) J Distance to Work 计算几何求圆与多边形相交面积模板
链接:https://www.nowcoder.com/acm/contest/141/J来源:牛客网 Eddy has graduated from college. Currently, he i ...
- [NetTopologySuite](2)任意多边形求交
任意多边形求交: private void btnPolygon_Click(object sender, EventArgs e) { , , , , , , , , , , , , , }; , ...
随机推荐
- span-wise drag/lift forces of cylinder
span-wise drag/lift forces of cylinder SR Description: Dear Sir/Madam, I am trying to simulate a 3 ...
- 【RQNOJ PID106】最大加权矩形(DP)
题目描述 给定一个正整数n( n<=100),然后输入一个N*N矩阵.求矩阵中最大加权矩形,即矩阵的每一个元素都有一权值,权值定义在整数集上.从中找一矩形,矩形大小无限制,是其中包含的所有元素的 ...
- ExecutorService 线程池 (转发)
1.ExecutorService java.util.concurrent.ExecutorService 接口.用来设置线程池并执行多线程任务.它有以下几个方法. Future<?> ...
- vscode调试angular2
调试步骤: 1.安装nodejs 2.安装vscode 3.vscode安装debugger for chrome插件 4.选择调试->打开调试配置,选择chrome配置,打开lauch.jso ...
- Git--使用须知123
详细的篇幅以后补充 安装篇: 设置篇: 由于我们大多数是windows程序员,那么,在使用git的过程前需要做一些设置项. 1.换行符自动转换. 查看:git config --global --li ...
- Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)
C. Petya and Spiders Little Petya loves training spiders. Petya has a board n × m in size. Each cell ...
- bzoj 4991 [Usaco2017 Feb]Why Did the Cow Cross the Road III(cdq分治,树状数组)
题目描述 Farmer John is continuing to ponder the issue of cows crossing the road through his farm, intro ...
- linux shell 获得当前程序的路径
filepath=$(cd "$(dirname "$0")"; pwd) 脚本文件的绝对路径存在了环境变量filepath中,可以用 echo $filepa ...
- 静态区间第k大(主席树)
POJ 2104为例(主席树入门题) 思想: 可持久化线段树,也叫作函数式线段树,也叫主席树(高大上). 可持久化数据结构(Persistent data structure):利用函数式编程的思想使 ...
- 一步步搭建java信息管理系统00 - 前言
开发前,先上效果图吧 信息管理系统,个人认为,以下几个因素是不可缺少的 多tab 因菜单比较多,右侧的树形一定要考虑,如果菜单还是多,那么顶部就要考虑起来了 以后想到什么,再添加吧. 看到easyui ...