题面

题意:给你一个半圆,和另一个多边形(可凹可凸),求面积交

题解:直接上板子,因为其实这个多边形不会穿过这个半圆,所以他和圆的交也就是和半圆的交

打的时候队友说凹的不行,不是板题,后面想想,圆与多边形面积交本来就是拆成有向三角形做的,所以无论凹凸了

 #include<bits/stdc++.h>
#define inf 1000000000000
#define M 100009
#define eps 1e-12
#define PI acos(-1.0)
using namespace std;
struct Point
{
double x,y;
Point(){}
Point(double xx,double yy){x=xx;y=yy;}
Point operator -(Point s){return Point(x-s.x,y-s.y);}
Point operator +(Point s){return Point(x+s.x,y+s.y);}
double operator *(Point s){return x*s.x+y*s.y;}
double operator ^(Point s){return x*s.y-y*s.x;}
}p[M];
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}
double len(Point a){return sqrt(a*a);}
double dis(Point a,Point b){return len(b-a);}//两点之间的距离
double cross(Point a,Point b,Point c)//叉乘
{
return (b-a)^(c-a);
}
double dot(Point a,Point b,Point c)//点乘
{
return (b-a)*(c-a);
}
int judge(Point a,Point b,Point c)//判断c是否在ab线段上(前提是c在直线ab上)
{
if (c.x>=min(a.x,b.x)
&&c.x<=max(a.x,b.x)
&&c.y>=min(a.y,b.y)
&&c.y<=max(a.y,b.y)) return ;
return ;
}
double area(Point b,Point c,double r)
{
Point a(0.0,0.0);
if(dis(b,c)<eps) return 0.0;
double h=fabs(cross(a,b,c))/dis(b,c);
if(dis(a,b)>r-eps&&dis(a,c)>r-eps)//两个端点都在圆的外面则分为两种情况
{
double angle=acos(dot(a,b,c)/dis(a,b)/dis(a,c));
if(h>r-eps) return 0.5*r*r*angle;else
if(dot(b,a,c)>&&dot(c,a,b)>)
{
double angle1=*acos(h/r);
return 0.5*r*r*fabs(angle-angle1)+0.5*r*r*sin(angle1);
}else return 0.5*r*r*angle;
}else
if(dis(a,b)<r+eps&&dis(a,c)<r+eps) return 0.5*fabs(cross(a,b,c));//两个端点都在圆内的情况
else//一个端点在圆上一个端点在圆内的情况
{
if(dis(a,b)>dis(a,c)) swap(b,c);//默认b在圆内
if(fabs(dis(a,b))<eps) return 0.0;//ab距离为0直接返回0
if(dot(b,a,c)<eps)
{
double angle1=acos(h/dis(a,b));
double angle2=acos(h/r)-angle1;
double angle3=acos(h/dis(a,c))-acos(h/r);
return 0.5*dis(a,b)*r*sin(angle2)+0.5*r*r*angle3;
}else
{
double angle1=acos(h/dis(a,b));
double angle2=acos(h/r);
double angle3=acos(h/dis(a,c))-angle2;
return 0.5*r*dis(a,b)*sin(angle1+angle2)+0.5*r*r*angle3;
}
}
}
int main()
{
int n;
double R;
scanf("%d%lf",&n,&R);
for(int i=;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
p[n+]=p[];
Point O(,);
for(int i=;i<=n+;i++) p[i]=p[i]-O;
O=Point(,);
double sum=;
for(int i=;i<=n;i++)
{
int j=i+;
double s=area(p[i],p[j],R);
if(cross(O,p[i],p[j])>) sum+=s; else sum-=s;
}
printf("%.12lf\n",fabs(sum));
return ;
}

Gym - 101208J 2013 ACM-ICPC World Finals J.Pollution Solution 圆与多边形面积交的更多相关文章

  1. ACM - ICPC World Finals 2013 C Surely You Congest

    原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 试题来源 ACM/ICPC World Fin ...

  2. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...

  3. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

  4. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  5. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  6. hduoj 4706 Children&#39;s Day 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4706 Children's Day Time Limit: 2000/1000 MS (Java/Others) ...

  7. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  8. hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  9. ACM - ICPC World Finals 2013 A Self-Assembly

    原题下载 : http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 这道题其实是2013年我AC的第一道题,非常的开心,这 ...

随机推荐

  1. HDU_1027_Ignatius and the Princess II_全排列

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  2. Android中Application类总结

    本文出处: 炎之铠csdn博客:http://blog.csdn.net/totond 炎之铠邮箱:yanzhikai_yjk@qq.com 本文原创,转载请注明本出处! 前言 最近的开发中经常使用到 ...

  3. JAVA经典题--计算一个字符串中每个字符出现的次数

    需求:  计算一个字符串中每个字符出现的次数 思路: 通过toCharArray()拿到一个字符数组--> 遍历数组,将数组元素作为key,数值1作为value存入map容器--> 如果k ...

  4. Bootstrap练习:可折叠下拉菜单

    代码: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UT ...

  5. 从CSV文件中读取jpg图片的URL地址并多线程批量下载

    很多时候,我们的网站上传图片时并没有根据内容进行文件夹分类,甚至会直接存储到阿里云的OSS或是七牛云等云存储上.这样,当我们需要打包图片时,就需要从数据库找寻分类图片,通过CURL进行下载.我最近刚刚 ...

  6. ansible - 基本用法

    目录 ansible - 01 一. 安装与使用 ansible命令格式 查看ansible生成的配置文件 ssh认证方式 ansible的第一个命令 弱口令校验 host-pattern的格式 模块 ...

  7. datetime库 日期与时间

    datetime是一个关于时间的库,主要包含的类有: date    日期对象,常用的属性有year,month,day time 时间对象,hour,minute,second,毫秒 datetim ...

  8. 申请SSL证书怎样验证域名所有权

    申请域名型证书时,系统将提供以下三种方式验证域名的所有权,请根据自己的实际情况选择其中一种进行域名验证: 1.管理员邮箱验证 系统会向你选择的管理员邮箱 发送验证邮件,能够收到验证邮件,并点击邮件中验 ...

  9. ReportNG 替换testng过程中遇到的问题

    1. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collectio ...

  10. (45). Spring Boot MyBatis连接Mysql数据库【从零开始学Spring Boot】

    大家在开发的时候,会喜欢jdbcTemplate操作数据库,有喜欢JPA操作数据库的,有喜欢MyBatis操作数据库的,对于这些我个人觉得哪个使用顺手就使用哪个就好了,并没有一定要使用哪个,个人在实际 ...