记录编号 230468 评测结果 AAAAAAAA
题目名称 [CEOI1999][POJ1379]逃离陷阱 最终得分 100
用户昵称 GravatarSatoshi 是否通过 通过
代码语言 C++ 运行时间 0.403 s
提交时间 2016-02-22 06:07:44 内存使用 0.25 MiB
显示代码纯文本
  1. #include <fstream>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <iomanip>
  5. #define N 1110
  6. using namespace std;
  7. typedef long double ld;
  8. ifstream cin("runaway.in");
  9. ofstream cout("runaway.out");
  10. int n;
  11. ld ansx,ansy,r,X[120],Y[120],R[120],INF=999999999;
  12. ld XO,YO;
  13. class point
  14. {
  15. public:
  16. ld x,y;
  17. void make(ld a,ld b)
  18. {
  19. x=a;
  20. y=b;
  21. }
  22. void print()
  23. {
  24. cout<<x<<' '<<y<<endl;
  25. }
  26. }P[N],dir[9];
  27. ld operator *(point a,point b)
  28. {
  29. ld solo;
  30. solo=a.x*b.x+a.y*b.y;
  31. return solo;
  32. }
  33. void print(ld x)
  34. {
  35. cout <<setprecision(1) <<std::fixed <<x;
  36. }
  37. point operator -(point a,point b)
  38. {
  39. point c;
  40. c.x=a.x-b.x;
  41. c.y=a.y-b.y;
  42. return c;
  43. }
  44. point operator +(point a,point b)
  45. {
  46. point c;
  47. c.x=a.x+b.x;
  48. c.y=a.y+b.y;
  49. return c;
  50. }
  51. point operator *(point a,ld b)
  52. {
  53. point c;
  54. c.x=a.x*b;
  55. c.y=a.y*b;
  56. return c;
  57. }
  58. ld len(point x){return sqrt(x*x);}
  59. ld dis(point x)
  60. {
  61. int i;
  62. point y;
  63. ld sum=INF,temp=0;
  64. for(i=1;i<=n;i++)
  65. {
  66. y=x-P[i];
  67. temp=len(y);
  68. //cout<<temp<<endl;
  69. if(temp<sum)sum=temp;
  70. }
  71. //cout<<sum<<endl;
  72. return sum;
  73. }
  74. void init()
  75. {
  76. dir[1].make(0,1);
  77. dir[2].make(1,0);
  78. dir[3].make(0,-1);
  79. dir[4].make(-1,0);
  80. dir[5].make(1,-1);
  81. dir[6].make(-1,1);
  82. dir[7].make(1,1);
  83. dir[8].make(-1,-1);
  84. srand(time(NULL));
  85. }
  86. void ansout()
  87. {
  88. cout<<"The safest point is (";
  89. print(ansx);
  90. cout<<',';
  91. print(ansy);
  92. cout<<").";
  93. //print(r);
  94. cout<<endl;
  95. }
  96. bool law(point O)
  97. {
  98. if(O.x>=0&&O.x<=XO&&O.y>=0&&O.y<=YO)return 1;
  99. return 0;
  100. }
  101. void work(point O)
  102. {
  103. ld step,ha,temp,base,basex,basey;
  104. point U,V,T;
  105. int i,k;
  106. U=T=O;
  107. r=0;
  108. base=6.5;
  109. for(k=1;k<=100;k++)
  110. {
  111. r=0;
  112. R[k]=0;
  113. U=O;
  114. for(step=100000;step>=0.0001;step/=base)
  115. {
  116. U=T;
  117. //out<<step<<endl;
  118. for(i=1;i<=8;i++)
  119. {
  120. V=U+dir[i]*step;
  121. if(!law(V))continue;
  122. temp=dis(V);
  123. if(temp>R[k])
  124. {
  125. X[k]=V.x;
  126. Y[k]=V.y;
  127. R[k]=temp;
  128. T=V;
  129. }
  130. }
  131. }
  132. base-=0.05;
  133. }
  134. r=0;
  135. for(k=1;k<=100;k++)
  136. {
  137. if(R[k]>r)
  138. {
  139. ansx=X[k];
  140. ansy=Y[k];
  141. r=R[k];
  142. }
  143. }
  144. //ansout();
  145. /*for(k=1;k<=1;k++)
  146. {
  147. U.make(ansx,ansy);
  148. for(step=-5;step<=5;step+=0.1)
  149. {
  150. for(ha=-5;ha<=5;ha+=0.1)
  151. {
  152. V.x=U.x+step;
  153. V.y=U.y+ha;
  154. temp=dis(V);
  155. if(r>temp)
  156. {
  157. ansx=V.x;
  158. ansy=V.y;
  159. r=temp;
  160. }
  161. }
  162. }
  163. U.make(ansx,ansy);
  164. for(step=-0.5;step<=0.5;step+=0.01)
  165. {
  166. for(ha=-0.5;ha<=0.5;ha+=0.01)
  167. {
  168. V.x=U.x+step;
  169. V.y=U.y+ha;
  170. temp=dis(V);
  171. if(r>temp)
  172. {
  173. ansx=V.x;
  174. ansy=V.y;
  175. r=temp;
  176. }
  177. }
  178. }
  179. U.make(ansx,ansy);
  180. for(step=-0.05;step<=0.05;step+=0.001)
  181. {
  182. for(ha=-0.05;ha<=0.05;ha+=0.001)
  183. {
  184. V.x=U.x+step;
  185. V.y=U.y+ha;
  186. temp=dis(V);
  187. if(r>temp)
  188. {
  189. ansx=V.x;
  190. ansy=V.y;
  191. r=temp;
  192. }
  193. }
  194. }
  195. }*/
  196. }
  197.  
  198. int main()
  199. {
  200. int T,i;
  201. point Q;
  202. init();
  203. T=1;
  204. while(T--)
  205. {
  206. cin>>XO>>YO>>n;
  207. for(i=1;i<=n;i++)cin>>P[i].x>>P[i].y;
  208. work(P[1]);
  209. ansout();
  210. }
  211. return 0;
  212. }