hdu 2892 Area
http://acm.hdu.edu.cn/showproblem.php?pid=2892
解题思路:
求多边形与圆的相交的面积是多少。
以圆心为顶点,将多边形划分为n个三角形。
接下来就求出每个三角形与圆相交的面积。
因为三角形的一个点是圆心,所以三角形的另外两个点与圆的情况有以下几种:
(1)两点都在圆里,三角形与圆相交的面积=三角形的面积。
(2)一个点在圆外,一个点在圆里,三角形与圆相交的面积=小三角形的面积+扇形面积
(3)两点都在圆外,又分为几种情况:
1、两点构成的线段与圆相交的点数0或1个时,三角形与圆相交的面积=扇形的面积
2.两点构成的线段与圆相交的点数2个时,三角形与圆相交的面积=大扇形面积+小三角形面积-小扇形的面积
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std; #define MAXN 100000+10
#define PI acos(-1.0)
#define EPS 0.00000001 int dcmp(double x){
if(fabs(x) < EPS)
return ;
return x < ? - : ;
} struct Point{
double x, y;
Point(double x = , double y = ): x(x), y(y) {}
}; struct Circle{
Point c;
double r;
Circle(Point c = Point(, ), double r = ): c(c), r(r) {}
}; typedef Point Vector; Vector operator + (Vector A, Vector B){
return Vector(A.x + B.x, A.y + B.y);
}
Vector operator - (Point A, Point B){
return Vector(A.x - B.x, A.y - B.y);
}
Vector operator * (Vector A, double p){
return Vector(A.x * p, A.y * p);
}
Vector operator / (Vector A, double p){
return Vector(A.x / p, A.y / p);
} double dot(Vector A, Vector B){
return A.x * B.x + A.y * B.y;
} double length(Vector A){
return sqrt(dot(A, A));
} double angle(Vector A, Vector B){
return acos(dot(A, B) / length(A) / length(B));
} double cross(Vector A, Vector B){
return A.x * B.y - A.y * B.x;
} Circle bomb;//炸弹爆炸的坐标及半径
Point p[MAXN];//岛屿的点
int n;//岛屿点数 double point_line_distance(Point P, Point A, Point B){//点到直线的距离
Vector AP = P - A, AB = B - A;
return fabs(cross(AP, AB) / length(AB));
} Point point_line_projection(Point P, Point A, Point B){//点在直线上的映射
Vector v = B - A;
return A + v * (dot(v, P - A) / dot(v, v));
} int circle_line_intersect(Circle C, Point A, Point B, vector<Point> &v){
double dist = point_line_distance(C.c, A, B);
int d = dcmp(dist - C.r);
if(d > ){
return ;
}
Point pro = point_line_projection(C.c, A, B);
if(d == ){
v.push_back(pro);
return ;
}
double len = sqrt(C.r * C.r - dist * dist);//勾股定理
Vector AB = B - A;
Vector l = AB / length(AB) * len;
v.push_back(pro + l);
v.push_back(pro - l);
return ;
} bool point_on_segment(Point P, Point A, Point B){//判断点在线段上
Vector PA = A - P, PB = B - P;
return dcmp(cross(PA, PB)) == && dcmp(dot(PA, PB)) <= ;
} double circle_delta_intersect_area(Circle C, Point A, Point B){
Vector CA = A - C.c, CB = B - C.c;
double da = length(CA), db = length(CB); da = dcmp(da - C.r), db = dcmp(db - C.r); if(da <= && db <= ){//三角形在圆里面
return fabs(cross(CA, CB)) * 0.5;
} vector<Point> v;
int num = circle_line_intersect(C, A, B, v);//圆和直线的关系
double carea = C.r * C.r * PI;
Point t;
if(da <= && db > ){//左边的点在圆里 右边的点在圆外
t = point_on_segment(v[], A, B) ? v[] : v[]; double area = fabs(cross(CA, t - C.c)) * 0.5, an = angle(CB, t - C.c);
return area + carea * an / PI / ;
}
if(da > && db <= ){//左边点在圆外 右边点在圆里
t = point_on_segment(v[], A, B) ? v[] : v[]; double area = fabs(cross(CB, t - C.c)) * 0.5, an = angle(CA, t - C.c);
return area + carea * an / PI / ;
}
//两个点都在圆外
if(num == ){
double bigarea = carea * angle(CA, CB) / PI / ,
smallarea = carea * angle(v[] - C.c, v[] - C.c) / PI / ,
deltaarea = fabs(cross(v[] - C.c, v[] - C.c)) * 0.5;
return bigarea + deltaarea - smallarea;
}
return carea * angle(CA, CB) / PI / ;//两点都在圆外 直线AB与圆交点1个或两个
} double circle_polygon_intersect_area(){//源于多边形相交面积
p[n] = p[];
double ans = ;
for(int i = ; i < n; i++ ){
double area = circle_delta_intersect_area( bomb, p[i], p[i + ] );
if(cross(p[i] - bomb.c, p[i + ] - bomb.c) < ){
area = -area;
}
ans += area;
}
return ans > ? ans : -ans;
} void solve(){
scanf("%d", &n );
for(int i = ; i < n; i++ ){
scanf("%lf%lf", &p[i].x, &p[i].y );
}
printf("%.2lf\n", circle_polygon_intersect_area() );
} int main(){
//freopen("data.in", "r", stdin );
double x, y, h, x1, y1, r;
while(~scanf("%lf%lf%lf", &x, &y, &h )){
scanf("%lf%lf%lf", &x1, &y1, &r ); double t = sqrt(0.2 * h);//h = 0.5 * G * t^2 重力加速度公式 bomb = Circle( Point(x1 * t + x, y1 * t + y), r ); solve();
}
return ;
}
hdu 2892 Area的更多相关文章
- hdu 2892 area (圆与多边形交面积)
Problem - 2892 这道题的做法是以圆心为原点,对多边形进行三角剖分.题目描述中,多边形的可能是顺时针或者是逆时针给出,不过在我的做法里,是用有向面积来计算的,和常见的多边形面积的求法类似, ...
- HDU - 2892:area (圆与多边形交 求面积)
pro:飞行员去轰炸一个小岛,给出炸弹落地点的位置信息,以及轰炸半径:按顺时针或者逆时针给出小岛的边界点. 求被轰炸的小岛面积. sol:即是求圆和多边形的面积交. (只会套板子的我改头换面,先理解然 ...
- hdu 2528 Area
2014-07-30 http://acm.hdu.edu.cn/showproblem.php?pid=2528解题思路: 求多边形被一条直线分成两部分的面积分别是多少.因为题目给的直线一定能把多边 ...
- hdu 4946 Area of Mushroom(凸包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946 Area of Mushroom Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 4946 Area of Mushroom(构造凸包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946 题目大意:在一个平面上有n个点p1,p2,p3,p4....pn,每个点可以以v的速度在平面上移 ...
- HDU 4946 Area of Mushroom 凸包
链接:pid=4946">http://acm.hdu.edu.cn/showproblem.php?pid=4946 题意:有n个人.在位置(xi,yi),速度是vi,假设对于某个点 ...
- HDU 4946 Area of Mushroom 凸包 第八次多校
题目链接:hdu 4946 题意:一大神有N个学生,各个都是小神,大神有个二次元空间,每一个小神都有一个初始坐标,如今大神把这些空间分给徒弟们,规则是假设这个地方有一个人比谁都先到这,那么这个地方就是 ...
- hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)
Area Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu 1451 Area in Triangle(计算几何 三角形)
Given a triangle field and a rope of a certain length (Figure-1), you are required to use the rope t ...
随机推荐
- Connection Management and Security
High Performance My SQL THIRD EDITION Each client connection gets its own thread within the server ...
- maven 的一些基本操作
maven install :把打出的包装载到本地仓库,package:是打包的意思 每当项目中的模块里的东西发生变化的时候,先install一下项目 ,在启用maven的tomcat插件就不会报错 ...
- [转]百度MP3音乐API接口及应用
当你在百度去搜索一首歌时,你会发现有种更简单的方法,嘿嘿,告诉你个秘密,百度有个不公开的API http://box.zhangmen.baidu.com/x?op=12&count=1&am ...
- ubuntu 制作deb 包
ubuntu下打包制作deb安装包 http://www.th7.cn/system/lin/201406/61012.shtml 2014-06-22 20:16:45CSDN-yangbing ...
- C# 操作Cookie类
1.Cookie操作类 using System; using System.Data; using System.Configuration;using System.Web;using Syste ...
- 蓝牙—GAP(Generic Access Profile)
1.简介 下图可见GAP在蓝牙协议中的位置和关系 LE中GAP共有四个角色: <1> Boradcaster:发送advertising 事件的设备 <2>Observer:接 ...
- 《linux内核设计与实现》读书笔记第一、二章
第一章 Linux内核简介 1.1 Unix的历史 1971年,Unix被移植到PDP-11型机中. 1973年,Unix操作系统用C语言改写——为Unix系统的广泛移植铺平了道路. 1977年,伯克 ...
- 设计模式:桥连模式(Bridge)
定 义:将抽象部分和它的实现部分分离,使它们可以独立的变化. 结构图: 实现类: //Implementor(实现)类 public abstract class Implementor { pu ...
- 常用jQuery代码02
一.each函数拿到每个元素的宽度 setTimeout(function () { $(".sticker_list img").each(function () { var W ...
- Magento订单打印(pdf格式)
Magento自身包含有:打印发票单,打印装箱单,打印退款单.这些都是基于西方国家的习惯来布置的.公司有个需求就是打印订单的四联单,PDF格式的,要一周内完成.刚接到这个任务时,觉得头大,因为对于PH ...