Feng Shui
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 3743   Accepted: 1150   Special Judge

Description

Feng shui is the ancient Chinese practice of placement and arrangement of space to achieve harmony with the environment. George has recently got interested in it, and now wants to apply it to his home and bring harmony to it.

There is a practice which says that bare floor is bad for living area since spiritual energy drains through it, so George purchased two similar round-shaped carpets (feng shui says that straight lines and sharp corners must be avoided). Unfortunately, he is unable to cover the floor entirely since the room has shape of a convex polygon. But he still wants to minimize the uncovered area by selecting the best placing for his carpets, and asks you to help.

You need to place two carpets in the room so that the total area covered by both carpets is maximal possible. The carpets may overlap, but they may not be cut or folded (including cutting or folding along the floor border) — feng shui tells to avoid straight lines.

Input

The first line of the input file contains two integer numbers n and r — the number of corners in George’s room (3 ≤ n ≤ 100) and the radius of the carpets (1 ≤ r ≤ 1000, both carpets have the same radius). The following n lines contain two integers xi and yi each — coordinates of the i-th corner (−1000 ≤ xiyi ≤ 1000). Coordinates of all corners are different, and adjacent walls of the room are not collinear. The corners are listed in clockwise order.

Output

Write four numbers x1y1x2y2 to the output file, where (x1y1) and (x2y2) denote the spots where carpet centers should be placed. Coordinates must be precise up to 4 digits after the decimal point.

If there are multiple optimal placements available, return any of them. The input data guarantees that at least one solution exists.

Sample Input

#1 5 2
-2 0
-5 3
0 8
7 3
5 0
#2 4 3
0 0
0 8
10 8
10 0

Sample Output

#1 -2 3 3 2.5
#2 3 5 7 3

Hint

Source

Northeastern Europe 2006, Northern Subregion

给你两个圆,半径相等,求放在一个凸多边形里两个圆不碰到边界的圆心。两个圆是可以重叠的。

半平面交,向内推进R,然后求组成多边形的最远的两个点即可。

  1. /* ***********************************************
  2. Author :kuangbin
  3. Created Time :2013/8/18 15:52:28
  4. File Name :F:\2013ACM练习\专题学习\计算几何\半平面交\POJ3384.cpp
  5. ************************************************ */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <iostream>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <queue>
  13. #include <set>
  14. #include <map>
  15. #include <string>
  16. #include <math.h>
  17. #include <stdlib.h>
  18. #include <time.h>
  19. using namespace std;
  20. const double eps = 1e-;
  21. const double PI = acos(-1.0);
  22. int sgn(double x)
  23. {
  24. if(fabs(x) < eps) return ;
  25. if(x < ) return -;
  26. else return ;
  27. }
  28. struct Point
  29. {
  30. double x,y;
  31. Point(){}
  32. Point(double _x,double _y)
  33. {
  34. x = _x; y = _y;
  35. }
  36. Point operator -(const Point &b)const
  37. {
  38. return Point(x - b.x, y - b.y);
  39. }
  40. double operator ^(const Point &b)const
  41. {
  42. return x*b.y - y*b.x;
  43. }
  44. double operator *(const Point &b)const
  45. {
  46. return x*b.x + y*b.y;
  47. }
  48. };
  49. struct Line
  50. {
  51. Point s,e;
  52. double k;
  53. Line(){}
  54. Line(Point _s,Point _e)
  55. {
  56. s = _s; e = _e;
  57. k = atan2(e.y - s.y,e.x - s.x);
  58. }
  59. Point operator &(const Line &b)const
  60. {
  61. Point res = s;
  62. double t = ((s - b.s)^(b.s - b.e))/((s - e)^(b.s - b.e));
  63. res.x += (e.x - s.x)*t;
  64. res.y += (e.y - s.y)*t;
  65. return res;
  66. }
  67. };
  68. //半平面交,直线的左边代表有效区域
  69. bool HPIcmp(Line a,Line b)
  70. {
  71. if(fabs(a.k - b.k) > eps)return a.k < b.k;
  72. return ((a.s - b.s)^(b.e - b.s)) < ;
  73. }
  74. Line Q[];
  75. void HPI(Line line[], int n, Point res[], int &resn)
  76. {
  77. int tot = n;
  78. sort(line,line+n,HPIcmp);
  79. tot = ;
  80. for(int i = ;i < n;i++)
  81. if(fabs(line[i].k - line[i-].k) > eps)
  82. line[tot++] = line[i];
  83. int head = , tail = ;
  84. Q[] = line[];
  85. Q[] = line[];
  86. resn = ;
  87. for(int i = ; i < tot; i++)
  88. {
  89. if(fabs((Q[tail].e-Q[tail].s)^(Q[tail-].e-Q[tail-].s)) < eps || fabs((Q[head].e-Q[head].s)^(Q[head+].e-Q[head+].s)) < eps)
  90. return;
  91. while(head < tail && (((Q[tail]&Q[tail-]) - line[i].s)^(line[i].e-line[i].s)) > eps)
  92. tail--;
  93. while(head < tail && (((Q[head]&Q[head+]) - line[i].s)^(line[i].e-line[i].s)) > eps)
  94. head++;
  95. Q[++tail] = line[i];
  96. }
  97. while(head < tail && (((Q[tail]&Q[tail-]) - Q[head].s)^(Q[head].e-Q[head].s)) > eps)
  98. tail--;
  99. while(head < tail && (((Q[head]&Q[head-]) - Q[tail].s)^(Q[tail].e-Q[tail].e)) > eps)
  100. head++;
  101. if(tail <= head + )return;
  102. for(int i = head; i < tail; i++)
  103. res[resn++] = Q[i]&Q[i+];
  104. if(head < tail - )
  105. res[resn++] = Q[head]&Q[tail];
  106. }
  107. Point p[];
  108. Line line[];
  109. //*两点间距离
  110. double dist(Point a,Point b)
  111. {
  112. return sqrt((a-b)*(a-b));
  113. }
  114. void change(Point a,Point b,Point &c,Point &d,double p)//将线段ab往左移动距离p
  115. {
  116. double len = dist(a,b);
  117. double dx = (a.y - b.y)*p/len;
  118. double dy = (b.x - a.x)*p/len;
  119. c.x = a.x + dx; c.y = a.y + dy;
  120. d.x = b.x + dx; d.y = b.y + dy;
  121. }
  122. int main()
  123. {
  124. //freopen("in.txt","r",stdin);
  125. //freopen("out.txt","w",stdout);
  126. int n;
  127. double r;
  128. while(scanf("%d%lf",&n,&r) == )
  129. {
  130. for(int i = ;i < n;i++)
  131. scanf("%lf%lf",&p[i].x,&p[i].y);
  132. reverse(p,p+n);
  133. for(int i = ;i < n;i++)
  134. {
  135. Point t1,t2;
  136. change(p[i],p[(i+)%n],t1,t2,r);
  137. line[i] = Line(t1,t2);
  138. }
  139. int resn;
  140. HPI(line,n,p,resn);
  141. int res1 = , res2 = ;
  142. for(int i = ;i < resn;i++)
  143. for(int j = i;j < resn;j++)
  144. if(dist(p[i],p[j]) > dist(p[res1],p[res2]))
  145. res1 = i, res2 = j;
  146. printf("%.5f %.5f %.5f %.5f\n",p[res1].x,p[res1].y,p[res2].x,p[res2].y);
  147. }
  148. return ;
  149. }

POJ 3384 Feng Shui (半平面交)的更多相关文章

  1. POJ 3384 Feng Shui 半平面交

    题目大意:一个人很信"Feng Shui",他要在房间里放两个圆形的地毯. 这两个地毯之间可以重叠,可是不能折叠,也不能伸到房间的外面.求这两个地毯可以覆盖的最大范围.并输出这两个 ...

  2. poj 3384 Feng Shui (Half Plane Intersection)

    3384 -- Feng Shui 构造半平面交,然后求凸包上最远点对. 这题的题意是给出一个凸多边形区域,要求在其中放置两个半径为r的圆(不能超出凸多边形区域),要求求出两个圆心,使得多边形中没有被 ...

  3. POJ 3384 Feng Shui

    http://poj.org/problem?id=3384 题意:给一个凸包,求往里面放两个圆(可重叠)的最大面积时的两个圆心坐标. 思路:先把凸包边往内推R,做半平面交,然后做旋转卡壳,此时得到最 ...

  4. POJ 3384 Feng Shui(计算几何の半平面交+最远点对)

    Description Feng shui is the ancient Chinese practice of placement and arrangement of space to achie ...

  5. POJ 3384 Feng Shui 凸包直径 + 半平面交

    G++一直没有过了 换成 C++果断A掉了...It's time to bet RP. 题意:给一个多边形,然后放进去两个圆,让两个圆的覆盖面积尽量最大,输出两个圆心的坐标. 思路:将多边形的边向里 ...

  6. poj 3335 Rotating Scoreboard - 半平面交

    /* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...

  7. POJ 3384 Feng Shui --直线切平面

    题意:房间是一个凸多边形,要在里面铺设两条半径为r的圆形地毯,可以重叠,现在要求分别铺设到哪,使地毯所占的地面面积最大. 解法:要使圆形地毯所占面积最大,圆形地毯一定是与边相切的,这样才能使尽量不重叠 ...

  8. POJ 2540 Hotter Colder --半平面交

    题意: 一个(0,0)到(10,10)的矩形,目标点不定,从(0,0)开始走,如果走到新一点是"Hotter",那么意思是离目标点近了,如果是"Colder“,那么就是远 ...

  9. POJ 3384 Feng Shui(半平面交向内推进求最远点对)

    题目链接 题意 : 两个圆能够覆盖的最大多边形面积的时候两个圆圆心的坐标是多少,两个圆必须在多边形内. 思路 : 向内推进r,然后求多边形最远的两个点就是能覆盖的最大面积. #include < ...

随机推荐

  1. JVM的分区+查看GC对象是否存活+3种GC算法+7种垃圾收集器+如何减少GC次数

    一.JVM的分区:   1.程序计数器(私有) 程序计数器是一块较小的内存分区,你可以把它看做当前线程所执行的字节码的指示器. 在虚拟机的概念模型里,字节码解释器工作时,就是通过改变计数器的值来选择下 ...

  2. 014 JVM面试题

    转自:http://www.importnew.com/31126.html 本文从 JVM 结构入手,介绍了 Java 内存管理.对象创建.常量池等基础知识,对面试中 JVM 相关的基础题目进行了讲 ...

  3. java实现ftp文件上传下载,解决慢,中文乱码,多个文件下载等问题

    //文件上传 public static boolean uploadToFTP(String url,int port,String username,String password,String ...

  4. java版云笔记(八)之关联映射

    Mybatis关联映射 通过数据库对象之间的关联关系,反映到到实体对象之间的引用. 加载多个表中的关联数据,封装到我们的实体对象中. 当业务对数据库进行关联查询. 关联 <association ...

  5. hbase学习(二)hbase单机和高可用完全分布式安装部署

    hbase版本 2.0.4  与hadoop兼容表http://hbase.apache.org/book.html#hadoop  我的 hadoop版本是3.1   1.单机版hbase 1.1解 ...

  6. csu 1769(数学)

    1769: 想打架吗?算我一个!所有人,都过来!(3) Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 262  Solved: 76[Submit][S ...

  7. js正则获取url参数,包含hash[#]和search[?]两种通用

    function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...

  8. 监控属性数组(Observables Arrays )

    如果你想发现并响应一个对象的改变,就应该用监控属性(observables).如果你想发现并响应一个集合的变化,就该用监控属性数组 (observableArray).监控属性数组在显示或编辑多个值以 ...

  9. HTTP缓存了解(一)

    引言 HTTP/1.1 200 OK X-Powered-By: Express Content-Type: text/html; charset=utf-8 Content-Length: 3 ET ...

  10. 隐马尔可夫模型(Hidden Markov Model)

    隐马尔可夫模型(Hidden Markov Model) 隐马尔可夫模型(Hidden Markov Model, HMM)是一个重要的机器学习模型.直观地说,它可以解决一类这样的问题:有某样事物存在 ...