题解

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

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

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

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

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

代码

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define pdi pair<db,int>
  6. #define mp make_pair
  7. #define pb push_back
  8. #define enter putchar('\n')
  9. #define space putchar(' ')
  10. #define eps 1e-8
  11. #define mo 974711
  12. #define MAXN 1000005
  13. //#define ivorysi
  14. using namespace std;
  15. typedef long long int64;
  16. typedef double db;
  17. template<class T>
  18. void read(T &res) {
  19. res = 0;char c = getchar();T f = 1;
  20. while(c < '0' || c > '9') {
  21. if(c == '-') f = -1;
  22. c = getchar();
  23. }
  24. while(c >= '0' && c <= '9') {
  25. res = res * 10 + c - '0';
  26. c = getchar();
  27. }
  28. res *= f;
  29. }
  30. template<class T>
  31. void out(T x) {
  32. if(x < 0) {x = -x;putchar('-');}
  33. if(x >= 10) {
  34. out(x / 10);
  35. }
  36. putchar('0' + x % 10);
  37. }
  38. int N,M;
  39. db ans;
  40. const db PI = acos(-1.0);
  41. bool dcmp(db a,db b) {
  42. return fabs(a - b) < eps;
  43. }
  44. struct Point {
  45. db x,y;
  46. Point(db _x = 0,db _y = 0) {
  47. x = _x;y = _y;
  48. }
  49. friend Point operator + (const Point &a,const Point &b) {
  50. return Point(a.x + b.x,a.y + b.y);
  51. }
  52. friend Point operator - (const Point &a,const Point &b) {
  53. return Point(a.x - b.x,a.y - b.y);
  54. }
  55. friend Point operator * (const Point &a,const db &d) {
  56. return Point(a.x * d,a.y * d);
  57. }
  58. friend Point operator / (const Point &a,const db &d) {
  59. return Point(a.x / d,a.y / d);
  60. }
  61. friend db operator * (const Point &a,const Point &b) {
  62. return a.x * b.y - a.y * b.x;
  63. }
  64. friend db dot(const Point &a,const Point &b) {
  65. return a.x * b.x + a.y * b.y;
  66. }
  67. db norm() {
  68. return sqrt(x * x + y * y);
  69. }
  70. }P[505],conv[505];
  71. void Calc(Point a,Point b,db R) {
  72. db f = 1;
  73. if(a * b < 0) f = -1;
  74. if(max(a.norm(),b.norm()) < R) return;
  75. db theta = acos(dot(a,b) / (a.norm() * b.norm()));
  76. db h = fabs(a * b) / (b - a).norm();
  77. if(h >= R) {ans += f * theta;return;}
  78. db beta = acos(dot(a - b,Point(-b.x,-b.y)) / ((a - b).norm() * b.norm()));
  79. db alpha = acos(dot(b - a,Point(-a.x,-a.y)) / ((a - b).norm() * a.norm()));
  80. db t = asin(h / R);
  81. db s = 0.0;
  82. if(t > alpha) s += (t - alpha);
  83. if(t > beta) s += (t - beta);
  84. s = min(s,theta);
  85. ans += f * s;
  86. }
  87. bool check(Point a,Point b) {
  88. Point c(1,0);
  89. if(a.y < b.y) swap(a,b);
  90. return c * a > 0 && b * c > 0 && b * a > 0;
  91. }
  92. void Init() {
  93. read(N);read(M);
  94. for(int i = 1 ; i <= N ; ++i) scanf("%lf%lf",&P[i].x,&P[i].y);
  95. for(int i = 1 ; i <= M ; ++i) scanf("%lf%lf",&conv[i].x,&conv[i].y);
  96. conv[M + 1] = conv[1];
  97. }
  98. void Solve() {
  99. for(int i = 1 ; i <= M ; ++i) {
  100. if(!dcmp(conv[i] * conv[i + 1],0)) {
  101. for(int j = 1 ; j <= N ; ++j) {
  102. if(!dcmp(P[j].norm(),0.0)) Calc(conv[i],conv[i + 1],P[j].norm());
  103. }
  104. }
  105. }
  106. for(int j = 1 ; j <= N ; ++j) {
  107. if(dcmp(P[j].norm(),0)) {
  108. bool flag = 1;int t = 0;
  109. for(int i = 1 ; i <= M ; ++i) {
  110. if(dcmp((conv[i] - P[j]) * (conv[i + 1] - P[j]),0.0)) {
  111. if(dot((conv[i] - P[j]),(conv[i + 1] - P[j])) <= 0) {
  112. flag = 0;break;
  113. }
  114. }
  115. else {
  116. if(dcmp(conv[i].y,0)) {
  117. if(conv[i].x > 0) ++t;
  118. }
  119. else t += check(conv[i],conv[i + 1]);
  120. }
  121. }
  122. if(flag && (t & 1)) ans += 2 * PI;
  123. }
  124. }
  125. ans /= 2 * PI;
  126. printf("%.5lf\n",ans);
  127. }
  128. int main() {
  129. #ifdef ivorysi
  130. freopen("f1.in","r",stdin);
  131. #endif
  132. Init();
  133. Solve();
  134. }

【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. oracle 查出一个表中字段值出现次数大于2的所有记录

    表web_order  列 name ,businesscode, a.account 周桥 18929609222 3754031157710000妙药 18929609233 3754031157 ...

  2. spring in action 学习笔记八:用@Primary 或者@Qualifier消除@Autowired引起的歧义现象

    首先解释一下@Primary和@Qualifier这两个注解的意思:@Primary的意思是在众多相同的bean中,优先使用用@Primary注解的bean.而@Qualifier这个注解则指定某个b ...

  3. 个推数据统计产品(个数)iOS集成实践

    最近业务方给我们部门提了新的需求,希望能一站式统计APP的几项重要数据.这次我们尝试使用的是个推(之前专门做消息推送的)旗下新推出的产品“个数·应用统计”,根据官方的说法,个推的数据统计产品通过专业的 ...

  4. 「Vue」路由

    Vue-routerrouter-link active-class类型: string默认值: "router-link-active"设置 链接激活时使用的 CSS 类名.默认 ...

  5. python常用模块-调用系统命令模块(subprocess)

    python常用模块-调用系统命令模块(subprocess) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. subproces基本上就是为了取代os.system和os.spaw ...

  6. [Spring] 学习Spring Boot之二:整合MyBatis并使用@Trasactional管理事务

    一.配置及准备工作 1.在 Maven 的 pom 文件中新增以下依赖: <dependency> <groupId>mysql</groupId> <art ...

  7. spring中set注入的一些小细节错误

    这是小白偶尔一直null指针的错误,调试了好久,原来是自己对spring注入的不够了解 我相信有很多跟我差不多的初学者会遇上,所以特地写出来,防止有人跟我一样.哈哈,也写上去,以防自己下次还犯这样的错 ...

  8. SHELL (1) —— shell脚本入门

    摘自:Oldboy Linux运维——SHELL编程实战 SHELL Shell是一个命令解释器,解释执行用户输入的命令及程序等,用户每输入一条命令,Shell就解释执行一条.这种从键盘以输入命令,就 ...

  9. C#_界面程序_数码游戏

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. 安装mongodb以及设置为windows服务 详细步骤

    我的win7 32的,注意版本要正确! 一.下载mongodb压缩包:mongodb-win32-i386-2.6.9.zip() 二.在D盘新建文件夹mongodb,将压缩我的解压文件放进去(有一个 ...