题意:如题

思路:离散。将所有交点求出来,相当于将多变形的边切成了很多条元边,对每条元边,有两种情况

  • 在圆内,答案加上此边长
  • 在圆外,答案加上此边相对于圆心的"有向转弧"

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "local.h"
#endif
#define X first
#define Y second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define mset(a, x) memset(a, x, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
typedef long long ll;
template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}
template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);} namespace ConstSet {
const double PI = acos(-1.0);
const double e = 2.718281828459045;
} const double eps = 1e-8;
struct Real {
double x;
double get() { return x; }
int read() { return scanf("%lf", &x); }
Real(const double &x) { this->x = x; }
Real() {}
Real abs() { return x > ? x : -x; } Real operator + (const Real &that) const { return Real(x + that.x);}
Real operator - (const Real &that) const { return Real(x - that.x);}
Real operator * (const Real &that) const { return Real(x * that.x);}
Real operator / (const Real &that) const { return Real(x / that.x);}
Real operator - () const { return Real(-x); } Real operator += (const Real &that) { return Real(x += that.x); }
Real operator -= (const Real &that) { return Real(x -= that.x); }
Real operator *= (const Real &that) { return Real(x *= that.x); }
Real operator /= (const Real &that) { return Real(x /= that.x); } bool operator < (const Real &that) const { return x - that.x <= -eps; }
bool operator > (const Real &that) const { return x - that.x >= eps; }
bool operator == (const Real &that) const { return x - that.x > -eps && x - that.x < eps; }
bool operator <= (const Real &that) const { return x - that.x < eps; }
bool operator >= (const Real &that) const { return x - that.x > -eps; } friend ostream& operator << (ostream &out, const Real &val) {
out << val.x;
return out;
}
friend istream& operator >> (istream &in, Real &val) {
in >> val.x;
return in;
}
}; struct Point {
Real x, y;
int read() { return scanf("%lf%lf", &x.x, &y.x); }
Point(const Real &x, const Real &y) { this->x = x; this->y = y; }
Point() {}
Point operator + (const Point &that) const { return Point(this->x + that.x, this->y + that.y); }
Point operator - (const Point &that) const { return Point(this->x - that.x, this->y - that.y); }
Real operator * (const Point &that) const { return x * that.x + y * that.y; }
Point operator * (const Real &that) const { return Point(x * that, y * that); }
Point operator / (const Real &that) { return Point(x / that, y / that); }
Point operator += (const Point &that) { return Point(this->x += that.x, this->y += that.y); }
Point operator -= (const Point &that) { return Point(this->x -= that.x, this->y -= that.y); }
Point operator *= (const Real &that) { return Point(x *= that, y *= that); }
Point operator /= (const Real &that) { return Point(x /= that, y /= that); } bool operator == (const Point &that) const { return x == that.x && y == that.y; } Real cross(const Point &that) const { return x * that.y - y * that.x; }
Real abs() { return sqrt((x * x + y * y).get()); }
};
typedef Point Vector; struct Segment {
Point a, b;
Segment(const Point &a, const Point &b) { this->a = a; this->b = b; }
Segment() {}
bool intersect(const Segment &that) const {
Point c = that.a, d = that.b;
Vector ab = b - a, cd = d - c, ac = c - a, ad = d - a, ca = a - c, cb = b - c;
return ab.cross(ac) * ab.cross(ad) < && cd.cross(ca) * cd.cross(cb) < ;
}
Point getSegmentIntersection(const Segment &that) const {
Vector u = a - that.a, v = b - a, w = that.b - that.a;
Real t = w.cross(u) / v.cross(w);
return a + v * t;
}
Real Distance(Point P) {
Point A = a, B = b;
if (A == B) return (P - A).abs();
Vector v1 = B - A, v2 = P - A, v3 = P - B;
if (v1 * v2 < ) return v2.abs();
if (v1 * v3 > ) return v3.abs();
return v1.cross(v2).abs() / v1.abs();
}
bool containPoint(const Point &p) const {
Vector ap = p - a, bp = p - b;
return ap * bp < ;
}
}; struct Line {
Point p;
Vector v;
Line(Point p, Vector v): p(p), v(v) {}
Line() {}
Point point(Real a) {
return p + v * a;
}
};
struct Circle {
Point c;
Real r;
Circle(Point c, Real r): c(c), r(r) {}
Circle() {}
void read() {
c.read();
scanf("%lf", &r.x);
}
Point point(Real a) {
return Point(c.x + r * cos(a.get()), c.y + r * sin(a.get()));
}
int getLineIntersection(Line L, vector<Point> &sol) {
Circle C = *this;
Real a = L.v.x, b = L.p.x - C.c.x, c = L.v.y, d = L.p.y - C.c.y;
Real e = a * a + c * c, f = (a * b + c * d) * , g = b * b + d * d - C.r * C.r;
Real delta = f * f - e * g * ;
Real t1, t2;
if (delta < ) return ;
if (delta == ) {
t1 = t2 = -f / (e * ); sol.push_back(L.point(t1));
return ;
}
t1 = (-f - sqrt(delta.get())) / (e * ); sol.push_back(L.point(t1));
t2 = (-f + sqrt(delta.get())) / (e * ); sol.push_back(L.point(t2));
return ;
}
Real turningAngle(Point a, Point b) {
Vector ca = a - c, cb = b - c;
if (ca.abs() == || cb.abs() == ) return ;//一个点和圆心重合,计算转角是没意义的
Real angle = acos((ca * cb / ca.abs() / cb.abs()).get());
return ca.cross(cb) >= ? angle : -angle;
}
}; const int maxn = 1e3 + ; Point p[maxn]; int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int n;
while (cin >> n, n) {
for (int i = ; i < n; i ++) {
p[i].read();
}
Circle c;
c.read();
vector<Point> vs;
for (int i = ; i < n; i ++) {
vs.pb(p[i]);
vector<Point> v;
Point a = p[i], b = p[(i + ) % n];
c.getLineIntersection(Line(a, b - a), v);
for (int i = ; i < v.size(); i ++) {
if (Segment(a, b).containPoint(v[i])) vs.pb(v[i]);
}
}
Real ans = ;
for (int i = ; i < vs.size(); i ++) {
int j = (i + ) % vs.size();
Point mid = (vs[i] + vs[j]) * 0.5;
Real length = (mid - c.c).abs();
if (length < c.r) ans += (vs[j] - vs[i]).abs();
else ans += c.r * -c.turningAngle(vs[i], vs[j]);
}
cout << (ll)(ans.get() + 0.5) << endl;
}
return ;
}

[hihoCoder1231 2015BeijingOnline]求圆与多边形公共部分的周长的更多相关文章

  1. 牛客网暑期ACM多校训练营(第三场) J Distance to Work 计算几何求圆与多边形相交面积模板

    链接:https://www.nowcoder.com/acm/contest/141/J来源:牛客网 Eddy has graduated from college. Currently, he i ...

  2. 简单几何(圆与多边形公共面积) UVALive 7072 Signal Interference (14广州D)

    题目传送门 题意:一个多边形,A点和B点,满足PB <= k * PA的P的范围与多边形的公共面积. 分析:这是个阿波罗尼斯圆.既然是圆,那么设圆的一般方程:(x + D/2) ^ 2 + (y ...

  3. HDU - 2892:area (圆与多边形交 求面积)

    pro:飞行员去轰炸一个小岛,给出炸弹落地点的位置信息,以及轰炸半径:按顺时针或者逆时针给出小岛的边界点. 求被轰炸的小岛面积. sol:即是求圆和多边形的面积交. (只会套板子的我改头换面,先理解然 ...

  4. Gym-101158J Cover the Polygon with Your Disk 计算几何 求动圆与多边形最大面积交

    题面 题意:给出小于10个点形成的凸多边形 和一个半径为r 可以移动的圆 求圆心在何处的面积交最大,面积为多少 题解:三分套三分求出圆心位置,再用圆与多边形面积求交 #include<bits/ ...

  5. hdu 5130(2014广州 圆与多边形相交模板)

    题意:一个很多个点p构成的多边形,pb <= pa * k时p所占区域与多边形相交面积 设p(x,y),       (x - xb)^2+(y - yb)^2 / (x - xa)^2+(y ...

  6. A Round Peg in a Ground Hole - POJ 1584 (判断凸多边形&判断点在多边形内&判断圆在多边形内)

    题目大意:首先给一个圆的半径和圆心,然后给一个多边形的所有点(多边形按照顺时针或者逆时针给的),求,这个多边形是否是凸多边形,如果是凸多边形在判断这个圆是否在这个凸多边形内.   分析:判断凸多边形可 ...

  7. codeforces 8D Two Friends 二分+ 判断三个圆是否有公共交点

    题目链接 有两个人x, y, 现在在A点, x要直接去B点, y要先去C点在去B点, 现在给出x, y两人可以行走的最大距离T1, T2, 求出他们从A点出发之后, 可以走的最长的公共路径. 我们先看 ...

  8. Gym - 101208J 2013 ACM-ICPC World Finals J.Pollution Solution 圆与多边形面积交

    题面 题意:给你一个半圆,和另一个多边形(可凹可凸),求面积交 题解:直接上板子,因为其实这个多边形不会穿过这个半圆,所以他和圆的交也就是和半圆的交 打的时候队友说凹的不行,不是板题,后面想想,圆与多 ...

  9. hdu 3982 Harry Potter and J.K.Rowling (半平面交 + 圆与多边形交)

    Problem - 3982 题意就是给出一个圆心在原点半径为R的圆形蛋糕,上面有一个cherry,对蛋糕切若干刀,最后要求求出有cherry的那块的面积占整个蛋糕的多少. 做法显而易见,就是一个半平 ...

随机推荐

  1. element-ui修改自定义主题

    官方文档:https://element.eleme.cn/#/zh-CN/component/custom-theme 简单更换主题色 打开:在线主题编辑器,仅修改主题色,点击右上角[切换主题色], ...

  2. wechall前十题

    今天开始打一打wechall 累了打wechall,不累的时候开始打buu 第一题:Get Sourced 查看源代码即可,拉到底部 第二题:Stegano 属于misc的范畴,直接下载下来,然后no ...

  3. Java封装 概述

    封装:是指隐藏对象的属性和实现细节,仅对外提供公共访问方式.好处:隐藏实现细节,提供公共的访问方式提高了代码的复用性提高安全性 封装原则:将不需要对外提供的内容都隐藏起来把属性隐藏,提供公共方法对其访 ...

  4. go获取当前项目下所有依赖包

    在设置好GOPATH,GOROOT的环境变量的情况下. 在项目配置好pkg.bin.src等这几个目录的情况,进入src目录. 在终端,输入:go get ./... 即可获得所有依赖包.

  5. 随笔之——伪类选择器:nth-child(n) 与 nth-of-type(n)的区别!!!

    话不多说!直接正题!!! 一.E:nth-child(n)///选中父元素中第(n)个元素.若第n个元素为E则选中:若第n个不为E则不选中.n可以为2n(偶数).2n+1(奇数).等... 二.E:n ...

  6. 基于jenkins自动打包并部署Tomcat环境

    传统网站部署的流程 在运维过程中,网站部署是运维的工作之一.传统的网站部署的流程大致分为:需求分析->原型设计->开发代码->提交代码->内网部署->内网测试->确 ...

  7. Ansible 配置文件详解

    # config file for ansible -- http://ansible.com/ # ============================================== #  ...

  8. Elasticsearch: 权威指南 » 深入搜索 » 多字段搜索 » 多数字段 good

      跨字段实体搜索  » 多数字段编辑 全文搜索被称作是 召回率(Recall) 与 精确率(Precision) 的战场: 召回率 --返回所有的相关文档:精确率 --不返回无关文档.目的是在结果的 ...

  9. Ubuntu Install Chinese Input Method

    为了提高在Linux系统使用中文输入的体验,安装搜狗拼音输入法. 确保键盘输入系统选中fcitx. 搜狗拼音输入法基于fcitx(Free Chinese Input Toy for X)框架,所以要 ...

  10. js世家委托详解

    事件原理 通过div0.addElementListener来调用:用法:div0.addElementListener(事件类型,事件回调函数,是否捕获时执行){}.1.事件类型(type):必须是 ...