给你一个凸多边形,问在里面距离凸边形最远的点。

方法就是二分这个距离,然后将对应的半平面沿着法向平移这个距离,然后判断是否交集为空,为空说明这个距离太大了,否则太小了,二分即可。

  1. #pragma warning(disable:4996)
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdio>
  5. #include <vector>
  6. #include <cmath>
  7. #include <string>
  8. #include <algorithm>
  9. using namespace std;
  10.  
  11. #define maxn 2500
  12. #define eps 1e-7
  13.  
  14. int n;
  15.  
  16. int dcmp(double x){
  17. return (x > eps) - (x < -eps);
  18. }
  19.  
  20. struct Point
  21. {
  22. double x, y;
  23. Point(){}
  24. Point(double _x, double _y) :x(_x), y(_y){}
  25. Point operator + (const Point &b) const{
  26. return Point(x + b.x, y + b.y);
  27. }
  28. Point operator - (const Point &b) const{
  29. return Point(x - b.x, y - b.y);
  30. }
  31. Point operator *(double d) const{
  32. return Point(x*d, y*d);
  33. }
  34. Point operator /(double d) const{
  35. return Point(x / d, y / d);
  36. }
  37. double det(const Point &b) const{
  38. return x*b.y - y*b.x;
  39. }
  40. double dot(const Point &b) const{
  41. return x*b.x + y*b.y;
  42. }
  43. Point rot90(){
  44. return Point(-y, x);
  45. }
  46. Point norm(){
  47. double len=sqrt(this->dot(*this));
  48. return Point(x, y) / len;
  49. }
  50. void read(){
  51. scanf("%lf%lf", &x, &y);
  52. }
  53. };
  54.  
  55. #define cross(p1,p2,p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))
  56. #define crossOp(p1,p2,p3) (dcmp(cross(p1,p2,p3)))
  57.  
  58. Point isSS(Point p1, Point p2, Point q1, Point q2){
  59. double a1 = cross(q1, q2, p1), a2 = -cross(q1, q2, p2);
  60. return (p1*a2 + p2*a1) / (a1 + a2);
  61. }
  62.  
  63. struct Border
  64. {
  65. Point p1, p2;
  66. double alpha;
  67. void setAlpha(){
  68. alpha = atan2(p2.y - p1.y, p2.x - p1.x);
  69. }
  70. };
  71.  
  72. bool operator < (const Border &a,const Border &b) {
  73. int c = dcmp(a.alpha - b.alpha);
  74. if (c != 0) {
  75. return c == 1;
  76. }
  77. else {
  78. return crossOp(b.p1, b.p2, a.p1) > 0;
  79. }
  80. }
  81.  
  82. bool operator == (const Border &a, const Border &b){
  83. return dcmp(a.alpha - b.alpha) == 0;
  84. }
  85.  
  86. Point isBorder(const Border &a, const Border &b){
  87. return isSS(a.p1, a.p2, b.p1, b.p2);
  88. }
  89.  
  90. Border border[maxn];
  91. Border que[maxn];
  92. int qh, qt;
  93. // check函数判断的是新加的半平面和由a,b两个半平面产生的交点的方向,若在半平面的左侧返回True
  94. bool check(const Border &a, const Border &b, const Border &me){
  95. Point is = isBorder(a, b);
  96. return crossOp(me.p1, me.p2, is) > 0;
  97. }
  98.  
  99. bool convexIntersection()
  100. {
  101. qh = qt = 0;
  102. sort(border, border + n);
  103. n = unique(border, border + n) - border;
  104. for (int i = 0; i < n; i++){
  105. Border cur = border[i];
  106. while (qh + 1 < qt&&!check(que[qt - 2], que[qt - 1], cur)) --qt;
  107. while (qh + 1 < qt&&!check(que[qh], que[qh + 1], cur)) ++qh;
  108. que[qt++] = cur;
  109. }
  110. while (qh + 1 < qt&&!check(que[qt - 2], que[qt - 1], que[qh])) --qt;
  111. while (qh + 1 < qt&&!check(que[qh], que[qh + 1], que[qt - 1])) ++qh;
  112. return qt - qh > 2;
  113. }
  114.  
  115. Point ps[maxn];
  116.  
  117. bool judge(double x)
  118. {
  119. for (int i = 0; i < n; i++){
  120. border[i].p1 = ps[i];
  121. border[i].p2 = ps[(i + 1) % n];
  122. }
  123. for (int i = 0; i < n; i++){
  124. Point vec = border[i].p2 - border[i].p1;
  125. vec=vec.rot90().norm();
  126. vec = vec*x;
  127. border[i].p1 = border[i].p1 + vec;
  128. border[i].p2 = border[i].p2 + vec;
  129. border[i].setAlpha();
  130. }
  131. return convexIntersection();
  132. }
  133.  
  134. int main()
  135. {
  136. while (cin>>n&&n)
  137. {
  138. for (int i = 0; i < n; i++){
  139. ps[i].read();
  140. }
  141. double l=0, r=100000000;
  142. while (dcmp(r-l)>0){
  143. double mid = (l + r) / 2;
  144. if (judge(mid)) l = mid;
  145. else r = mid;
  146. }
  147. printf("%.6lf\n", l);
  148. }
  149. return 0;
  150. }

POJ3525 Most Distant Point from the Sea(半平面交)的更多相关文章

  1. POJ 3525 Most Distant Point from the Sea [半平面交 二分]

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5153   ...

  2. LA 3890 Most Distant Point from the Sea(半平面交)

    Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...

  3. POJ 3525 Most Distant Point from the Sea (半平面交)

    Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...

  4. poj3525 Most Distant Point from the Sea

    题目描述: vjudge POJ 题解: 二分答案+半平面交. 半径范围在0到5000之间二分,每次取$mid$然后平移所有直线,判断半平面交面积是否为零. 我的eps值取的是$10^{-12}$,3 ...

  5. POJ 3525 Most Distant Point from the Sea (半平面交+二分)

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3476   ...

  6. POJ 3525/UVA 1396 Most Distant Point from the Sea(二分+半平面交)

    Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...

  7. POJ3525-Most Distant Point from the Sea(二分+半平面交)

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3955   ...

  8. 【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)

    按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径. 二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了. 平移直线就是对于向量ab,因为是逆时针的,向中 ...

  9. 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea

    题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...

随机推荐

  1. Python学习教程(learning Python)--1.2.4 Python格式化输出科学计数

    Python在浮点数据输出时,可以采用科学计数法的方式输出. 现举两个例子说明一下如何使用. eg1. 无精度要求的科学计数法浮点数据输出 >>> print(format(1234 ...

  2. 刀哥多线程之并发队列gcd-05-dispatch_queue_concurrent

    并发队列 特点 以先进先出的方式,并发调度队列中的任务执行 如果当前调度的任务是同步执行的,会等待任务执行完成后,再调度后续的任务 如果当前调度的任务是异步执行的,同时底层线程池有可用的线程资源,会再 ...

  3. 对云风 cstring 第二次解析

    前言 从明天起 关心粮食和蔬菜 我有一所房子 面朝大海 春暖花开 本文前提条件 1.了解 posix 线程 2.了解 原子操作 3.具备简单C基础,或者 你也敲一遍. 如果上面不太清楚,你可以翻看我以 ...

  4. SQL基础篇——如何搭建一个数据库

    特别提醒:所有的新建数据库,表,行,列都可以通过对象资源管理器操作,下面所讲的为查询操作方法 一.新建数据库 使用CREATE DATABASE语句建立数据库: 新建查询-- CREATE DATAB ...

  5. poj 2887 Big String

    题目连接 http://poj.org/problem?id=2887 Big String Description You are given a string and supposed to do ...

  6. 数据密集型 和 cpu密集型 event loop

    Node.js在官网上是这样定义的:“一个搭建在Chrome JavaScript运行时上的平台,用于构建高速.可伸缩的网络程序.Node.js采用的事件驱动.非阻塞I/O模型使它既轻量又高效,是构建 ...

  7. TFS(Taobao File System)安装方法

    文章目录: 一.TFS(Taobao File System)安装方法 二.TFS(Taobao File System)配置dataServer.分区.挂载数据盘 三.TFS(Taobao File ...

  8. C++输出四则运算设计题的思路

    一,(1)题目避免重复:使用srand(seed)函数进行随机化,随seed的不同,可以产生不同的随机数二,(1)控制数量:输入变量n控制三,(1)控制是否有乘除:(chengchu=0,没有乘除:c ...

  9. NABC需求分析

    我们团队项目为7-magic,在这个七巧板项目中,我们团队的这个项目有许多的特点,我就其中的一个特点:用户可以自主的用七巧板设计自己想象出的图形,并与大家分享. N (Need 需求): 你的创意解决 ...

  10. 课堂练习:给定一个十进制的正整数,写下从1开始,到N的所有整数,然后数一下其中出现“1”的个数。

    题目 1 给定一个十进制的正整数,写下从1开始,到N的所有整数,然后数一下其中出现“1”的个数. 2 要求: (1) 写一个函数 f(N) ,返回1 到 N 之间出现的“1”的个数.例如 f(12)  ...