ZOJ 2675 Little Mammoth(计算几何)
圆形与矩形截面的面积
三角仍然可以做到这一点
代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std; const double eps = 1e-8;
const double pi = acos(-1.0); int dcmp(double x)
{
if(x > eps) return 1;
return x < -eps ? -1 : 0;
} struct Point
{
double x, y;
Point(){x = y = 0;}
Point(double a, double b)
{x = a, y = b;}
inline void read()
{scanf("%lf%lf", &x, &y);}
inline Point operator-(const Point &b)const
{return Point(x - b.x, y - b.y);}
inline Point operator+(const Point &b)const
{return Point(x + b.x, y + b.y);}
inline Point operator*(const double &b)const
{return Point(x * b, y * b);}
inline double dot(const Point &b)const
{return x * b.x + y * b.y;}
inline double cross(const Point &b, const Point &c)const
{return (b.x - x) * (c.y - y) - (c.x - x) * (b.y - y);}
inline double Dis(const Point &b)const
{return sqrt((*this - b).dot(*this - b));}
inline bool InLine(const Point &b, const Point &c)const//三点共线
{return !dcmp(cross(b, c));}
inline bool OnSeg(const Point &b, const Point &c)const//点在线段上,包含端点
{return InLine(b, c) && (*this - c).dot(*this - b) < eps;}
}; inline double min(double a, double b)
{return a < b ? a : b;}
inline double max(double a, double b)
{return a > b ? a : b;}
inline double Sqr(double x)
{return x * x;}
inline double Sqr(const Point &p)
{return p.dot(p);} Point LineCross(const Point &a, const Point &b, const Point &c, const Point &d)
{
double u = a.cross(b, c), v = b.cross(a, d);
return Point((c.x * v + d.x * u) / (u + v), (c.y * v + d.y * u) / (u + v));
} double LineCrossCircle(const Point &a, const Point &b, const Point &r,
double R, Point &p1, Point &p2)
{
Point fp = LineCross(r, Point(r.x + a.y - b.y, r.y + b.x - a.x), a, b);
double rtol = r.Dis(fp);
double rtos = fp.OnSeg(a, b) ? rtol : min(r.Dis(a), r.Dis(b));
double atob = a.Dis(b);
double fptoe = sqrt(R * R - rtol * rtol) / atob;
if(rtos > R - eps) return rtos;
p1 = fp + (a - b) * fptoe;
p2 = fp + (b - a) * fptoe;
return rtos;
} double SectorArea(const Point &r, const Point &a, const Point &b, double R)
//不大于180度扇形面积。r->a->b逆时针
{
double A2 = Sqr(r - a), B2 = Sqr(r - b), C2 = Sqr(a - b);
return R * R * acos((A2 + B2 - C2) * 0.5 / sqrt(A2) / sqrt(B2)) * 0.5;
} double TACIA(const Point &r, const Point &a, const Point &b, double R)
//TriangleAndCircleIntersectArea。逆时针,r为圆心
{
double adis = r.Dis(a), bdis = r.Dis(b);
if(adis < R + eps && bdis < R + eps) return r.cross(a, b) * 0.5;
Point ta, tb;
if(r.InLine(a, b)) return 0.0;
double rtos = LineCrossCircle(a, b, r, R, ta, tb);
if(rtos > R - eps) return SectorArea(r, a, b, R);
if(adis < R + eps) return r.cross(a, tb) * 0.5 + SectorArea(r, tb, b, R);
if(bdis < R + eps) return r.cross(ta, b) * 0.5 + SectorArea(r, a, ta, R);
return r.cross(ta, tb) * 0.5 +
SectorArea(r, a, ta, R) + SectorArea(r, tb, b, R);
} const int N = 505; Point p[N], o; double SPICA(int n, Point r, double R)//SimplePolygonIntersectCircleArea
{
int i;
double res = 0, if_clock_t;
for(i = 0; i < n; ++ i)
{
if_clock_t = dcmp(r.cross(p[i], p[(i + 1) % n]));
if(if_clock_t < 0) res -= TACIA(r, p[(i + 1) % n], p[i], R);
else res += TACIA(r, p[i], p[(i + 1) % n], R);
}
return fabs(res);
} double r; int main() {
int bo = 0;
while (~scanf("%lf%lf%lf", &o.x, &o.y, &r)) {
if (bo) printf("\n");
else bo = 1;
double x1, y1, x2, y2;
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
if (x1 > x2) swap(x1, x2);
if (y1 > y2) swap(y1, y2);
p[0] = Point(x1, y1);
p[1] = Point(x1, y2);
p[2] = Point(x2, y2);
p[3] = Point(x2, y1);
printf("%.10f\n", SPICA(4, o, r));
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
ZOJ 2675 Little Mammoth(计算几何)的更多相关文章
- ZOJ 1696 Viva Confetti 计算几何
计算几何:按顺序给n个圆覆盖.问最后能够有几个圆被看见.. . 对每一个圆求和其它圆的交点,每两个交点之间就是可能被看到的圆弧,取圆弧的中点,往外扩展一点或者往里缩一点,从上往下推断有没有圆能够盖住这 ...
- zoj 3537 区间dp+计算几何
题意:给定n个点的坐标,先问这些点是否能组成一个凸包,如果是凸包,问用不相交的线来切这个凸包使得凸包只由三角形组成,根据costi, j = |xi + xj| * |yi + yj| % p算切线的 ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- July 【补题】
A(zoj 3596) bfs,记忆搜都可以, 按余数来记录状态. B(zoj 3599) 博弈,跳过 C(zoj 3592) 简单dp,题意不好懂 D(zoj 3602) 子树哈希, 对根的左右儿子 ...
- ZOJ 3157 Weapon --计算几何+树状数组
题意:给一些直线,问这些直线在直线x=L,x=R之间有多少个交点. 讲解见此文:http://blog.sina.com.cn/s/blog_778e7c6e0100q64a.html 首先将直线分别 ...
- ZOJ 3203 Light Bulb (三分+计算几何)
B - Light Bulb Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...
- ZOJ 1081 Within(点是否在多边形内)| 计算几何
ZOJ 1081 Within 我使用的是"射线法":从该点出发,作一条向左的水平射线,与多边形的边的交点有奇数个则点在多边形内. 需要注意的点: 如果点在多边形的边上特判. 考虑 ...
- zoj 1081:Points Within(计算几何,判断点是否在多边形内,经典题)
Points Within Time Limit: 2 Seconds Memory Limit: 65536 KB Statement of the Problem Several dra ...
- zoj 3716 Ribbon Gymnastics【神奇的计算几何】
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3716 来源:http://acm.hust.edu.cn/vjudg ...
随机推荐
- 仿微沟道效应,主要actionbar有些知识
仿微沟道效应,主要actionbar有些知识 1.新actionBar的menu <menu xmlns:android="http://schemas.android.com/apk ...
- HDU 4946 Area of Mushroom 凸包
链接:pid=4946">http://acm.hdu.edu.cn/showproblem.php?pid=4946 题意:有n个人.在位置(xi,yi),速度是vi,假设对于某个点 ...
- 颜色(color)转换为三刺激值(r/g/b)(干股)
//颜色转换 ##665522 - 三色值 + (UIColor *)setFontColorWithString:(NSString *)color { NSString *cString ...
- OpenGL路(四)自制的图形功能(立方体、汽缸、圆锥)
#include <gl/glut.h> #include <gl/GLU.h> #include <gl/GL.h> #pragma comment(lib, & ...
- 【源代码】LinkedList源代码分析
//----------------------------------------------------------- 转载请注明出处:http://blog.csdn.net/chdjj by ...
- hdu 2067 兔子板
兔子板 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- JavaScript的隐式转换
原文:JavaScript的隐式转换 JavaScript的数据类型分为六种,分别为null,undefined,boolean,string,number,object.object是引用类型,其它 ...
- Codeforces 437A The Child and Homework
题目链接:Codeforces 437A The Child and Homework 少看了一个条件,最后被HACK掉到203名,要不然就冲到100多一点了==.. 做这个题收获最大的是英语,A t ...
- Bootstrap(2)整体架构
Bootstrap(2)整体架构 大多数Bootstrap的使用者都认为Bootstrap只提供了CSS组件 和JavaScript插件,其实CSS组件和JavaScript插件只是Bootstrap ...
- iis7、iis8配置备份还原
原文 iis7.iis8配置备份还原 方法1: 1.打开我们的IIS管理器,在功能视图里找到“共享的配置”这个功能然后双击进入. 2.进入“共享的配置”后单机右上方的“导出配置”选项,选择导出配置文件 ...