题意:如题

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

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

#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. Crossing River POJ过河问题

    A group of N people wishes to go across a river with only one boat, which can at most carry two pers ...

  2. Cucumber(4)——jenkins的集成

    目录 回顾 必备知识 集成方法 回顾 在上几节中,关于cucumber的知识我已经全部的介绍完了,但是近期,jenkins大行其道,在工作上面能为我们节省大量的时间. 所以在本节中,我会介绍cucum ...

  3. 文本文件的合并操作方法 - Python

    我们有时候,看到几k的日志文件,一大堆,一个一个打开又很麻烦,少看几个,又担心遗漏,这个时候,如果有一个可以合并所有文本文件的工具就好了. 下面这个代码就可以实现,它不局限于.txt格式,基本上字符型 ...

  4. 【arithmetic】搜索插入位置

    给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会被按顺序插入的位置 可以假设数组中无重复元素. 示例 1: 输入: [1,3,5,6], 5 输出: ...

  5. Docker 搭建 ELK 集群步骤

    前言 本篇文章主要介绍在两台机器上使用 Docker 搭建 ELK. 正文 环境 CentOS 7.7 系统 Docker version 19.03.8 docker-compose version ...

  6. Makefile 中引用多个 include 路径

    LIB=-L/usr/informix/lib/c++ INC=-I/usr/informix/incl/c++ -I/opt/informix/incl/public default: main m ...

  7. [Qt] 数字转换为 QString

    数字转换为 QString 静态函数 number(), asprintf() 公用函数 setNum(), sprintf() QString::number(), setNum() 可转换进制

  8. 标准库os

    os模块 提供对操作系统进行调用的接口 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 os ...

  9. CSS开发技巧(一):button样式设置

    button样式需要注意的有几点: 1.建议有一个最小宽度,以免在文字很少时使得按钮过于窄,宽高不协调: 2.建议有一个padding,以免内部文本显得过于拥挤: 2.hover时需要有颜色变化,以告 ...

  10. Radware:上周五美国大规模DDoS攻击是如何发生的

    10月21日上午,Dyn遭受到拒绝服务(DoS)攻击,造成了托管DNS网络的中断.成千上万的网站因此变得不可访问,其中包括Amazon EC2.当天晚些时候,当攻击者发起第二轮针对Dyn DNS系统的 ...