题解

我们把这个多边形三角形剖分了,和统计多边形面积一样

每个三角形有个点是原点,把原点所对应的角度算出来,记为theta

对于一个点,相当于半径为这个点到原点的一个圆,圆弧上的弧度为theta的一部分

相当于一条直线和这个小圆弧求交,直接算出有交的角度然后累加最后除2PI即可

可以拿余弦定理爆算(反着也不是你自己算

代码

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,M;
db ans;
const db PI = acos(-1.0);
bool dcmp(db a,db b) {
return fabs(a - b) < eps;
}
struct Point {
db x,y;
Point(db _x = 0,db _y = 0) {
x = _x;y = _y;
}
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x + b.x,a.y + b.y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x - b.x,a.y - b.y);
}
friend Point operator * (const Point &a,const db &d) {
return Point(a.x * d,a.y * d);
}
friend Point operator / (const Point &a,const db &d) {
return Point(a.x / d,a.y / d);
}
friend db operator * (const Point &a,const Point &b) {
return a.x * b.y - a.y * b.x;
}
friend db dot(const Point &a,const Point &b) {
return a.x * b.x + a.y * b.y;
}
db norm() {
return sqrt(x * x + y * y);
}
}P[505],conv[505];
void Calc(Point a,Point b,db R) {
db f = 1;
if(a * b < 0) f = -1;
if(max(a.norm(),b.norm()) < R) return;
db theta = acos(dot(a,b) / (a.norm() * b.norm()));
db h = fabs(a * b) / (b - a).norm();
if(h >= R) {ans += f * theta;return;}
db beta = acos(dot(a - b,Point(-b.x,-b.y)) / ((a - b).norm() * b.norm()));
db alpha = acos(dot(b - a,Point(-a.x,-a.y)) / ((a - b).norm() * a.norm()));
db t = asin(h / R);
db s = 0.0;
if(t > alpha) s += (t - alpha);
if(t > beta) s += (t - beta);
s = min(s,theta);
ans += f * s;
}
bool check(Point a,Point b) {
Point c(1,0);
if(a.y < b.y) swap(a,b);
return c * a > 0 && b * c > 0 && b * a > 0;
}
void Init() {
read(N);read(M);
for(int i = 1 ; i <= N ; ++i) scanf("%lf%lf",&P[i].x,&P[i].y);
for(int i = 1 ; i <= M ; ++i) scanf("%lf%lf",&conv[i].x,&conv[i].y);
conv[M + 1] = conv[1];
}
void Solve() {
for(int i = 1 ; i <= M ; ++i) {
if(!dcmp(conv[i] * conv[i + 1],0)) {
for(int j = 1 ; j <= N ; ++j) {
if(!dcmp(P[j].norm(),0.0)) Calc(conv[i],conv[i + 1],P[j].norm());
}
}
}
for(int j = 1 ; j <= N ; ++j) {
if(dcmp(P[j].norm(),0)) {
bool flag = 1;int t = 0;
for(int i = 1 ; i <= M ; ++i) {
if(dcmp((conv[i] - P[j]) * (conv[i + 1] - P[j]),0.0)) {
if(dot((conv[i] - P[j]),(conv[i + 1] - P[j])) <= 0) {
flag = 0;break;
}
}
else {
if(dcmp(conv[i].y,0)) {
if(conv[i].x > 0) ++t;
}
else t += check(conv[i],conv[i + 1]);
}
}
if(flag && (t & 1)) ans += 2 * PI;
}
}
ans /= 2 * PI;
printf("%.5lf\n",ans);
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Init();
Solve();
}

【LOJ】#6437. 「PKUSC2018」PKUSC的更多相关文章

  1. 【LOJ】#6434. 「PKUSC2018」主斗地

    题解 什么,我这题竟然快到了LOJ rk1???? 搜起来有点麻烦,不过感觉还是比斗地主好下手(至今没敢写斗地主 首先是暴力搜牌型,最多\(3^{16}\)(什么判解还要复杂度怂成一团)的样子?? 然 ...

  2. 【LOJ】#6436. 「PKUSC2018」神仙的游戏

    题解 感觉智商为0啊QAQ 显然对于一个长度为\(len\)的border,每个点同余\(n - len\)的部分必然相等 那么我们求一个\(f[a]\)数组,如果存在\(s[x] = 0\)且\(s ...

  3. 【LOJ】#6435. 「PKUSC2018」星际穿越

    题解 想出70的大众分之后就弃疗了,正解有点神仙 就是首先有个比较显然的结论,就是要么是一直往左走,要么是走一步右边,然后一直往左走 根据这个可以结合RMQ写个70分的暴力 我们就考虑,最优的话显然是 ...

  4. 【LOJ】#6433. 「PKUSC2018」最大前缀和

    题解 神仙的状压啊QAQ 设一个\(f[S]\)表示数字的集合为\(S\)时\(sum[S]\)为前缀最大值的方案数 \(g[S]\)表示数字集合为\(S\)时所有前缀和都小于等于0的方案数 答案就是 ...

  5. 【LOJ】#6432. 「PKUSC2018」真实排名

    题解 简单分析一下,如果这个选手成绩是0,直接输出\(\binom{n}{k}\) 如果这个选手的成绩没有被翻倍,那么找到大于等于它的数(除了它自己)有a个,翻倍后不大于它的数有b个,那么就从这\(a ...

  6. 【LOJ】#2210. 「HNOI2014」江南乐

    LOJ#2210. 「HNOI2014」江南乐 感觉是要推sg函数 发现\(\lfloor \frac{N}{i}\rfloor\)只有\(O(\sqrt{N})\)种取值 考虑把这些取值都拿出来,能 ...

  7. 【LOJ】#3098. 「SNOI2019」纸牌

    LOJ#3098. 「SNOI2019」纸牌 显然选三个以上的连续牌可以把他们拆分成三个三张相等的 于是可以压\((j,k)\)为有\(j\)个连续两个的,有\(k\)个连续一个的 如果当前有\(i\ ...

  8. 【LOJ】#3103. 「JSOI2019」节日庆典

    LOJ#3103. 「JSOI2019」节日庆典 能当最小位置的值一定是一个最小后缀,而有用的最小后缀不超过\(\log n\)个 为什么不超过\(\log n\)个,看了一下zsy的博客.. 假如\ ...

  9. 【LOJ】#3102. 「JSOI2019」神经网络

    LOJ#3102. 「JSOI2019」神经网络 首先我们容易发现就是把树拆成若干条链,然后要求这些链排在一个环上,同一棵树的链不相邻 把树拆成链可以用一个简单(但是需要复杂的分类讨论)的树背包实现 ...

随机推荐

  1. 【USACO 1.4】Combination Lock

    /* TASK:combo LANG:C++ URL:http://train.usaco.org/usacoprob2?a=E6RZnAhV9zn&S=combo SOLVE:自己做,想的是 ...

  2. 洛谷 P1310 表达式的值 解题报告

    P1310 表达式的值 题目描述 对于1 位二进制变量定义两种运算: 运算的优先级是: 先计算括号内的,再计算括号外的. "× "运算优先于"⊕"运算,即计算表 ...

  3. jQuery源码之 empty与html('')的区别

    empty: function() { var elem, i = 0; for ( ; (elem = this[i]) != null; i++ ) { // Remove element nod ...

  4. create-react-app脚手架使用

    1.安装脚手架和路由 npm i -g create-react-app npm i -S react-router react-router-dom 2.创建新项目 create-react-app ...

  5. C语言复习---零散补充

    一:double和float使用scanf获取数据 printf输出float和double都可以用%f,double还可以用%lf. 2 scanf输入float用%f,double输入用%lf,不 ...

  6. Hadoop源码阅读-HDFS-day2

    昨天看到了AbstractFileSystem,也知道应用访问文件是通过FileContext这个类,今天来看这个类的源代码,先看下这个类老长的注释说明 /** * The FileContext c ...

  7. 什么是HTTP协议

    什么是Http协议Http协议即超文本传送协议 (HTTP-Hypertext transfer protocol) .它定义了浏览器(即万维网客户进程)怎样向万维网服务器请求万维网文档,以及服务器怎 ...

  8. weblogic11G 修改密码

    weblogic11的登录密码修改方法: 1. 登陆到weblogic后选中domain structure下的security Realms(如图一)   (图一) 详情如图二: (图二) 2. 双 ...

  9. ThinkPHP框架学习(一)

    这几天呢,断断续续地在看孙叔华老师的ThinkPHP教程,期间还做了一些其他事情,出去办了点事,总结总结下一学期规划等等,不知不觉间又过去了大半个星期.现在呢,看完了一天的教程,在这里,还是希望稍微总 ...

  10. JMS学习(三)ActiveMQ Message Persistence

    1,JMS规范支持两种类型的消息传递:persistent and non-persistent.ActiveMQ在支持这两种类型的传递方式时,还支持消息的恢复.中间状态的消息(message are ...