最小覆盖圆算法。看着题解半蒙半抄的搞过去了…

主要参考以下
http://blog.csdn.net/acdreamers/article/details/9406735
http://blog.csdn.net/lthyxy/article/details/6661250
http://blog.himdd.com/archives/2666

其中有一个求外心的过程是错的…害我调了好久…还把x和y搞反…可是就算是错的我居然过了80%的数据…

仍然几个疑问:

(1)最小覆盖圆算法时间复杂度的证明

(2)椭圆的中心未定的情况下,为什么以原点为中心旋转&缩放即可?(我几何不好QAQ)

  1. program amplifier;
  2. uses math;
  3. type point=record
  4. x,y:extended;
  5. end;
  6. const maxn=;
  7. pi=3.14159265358979;
  8. eps=0.00000001;
  9. var n,i,p:longint;
  10. a,r:extended;
  11. o:point;
  12. v:array[..maxn+] of point;
  13. procedure rotate(i:longint);
  14. var x,y:extended;
  15. begin
  16. x:=v[i].x*cos(-a)-v[i].y*sin(-a);
  17. y:=v[i].x*sin(-a)+v[i].y*cos(-a);
  18. v[i].x:=x/p;
  19. v[i].y:=y;
  20. end;
  21.  
  22. function circumcenter(p,q,r:point):point;
  23. var a,b,c,d,e,f:extended;
  24. begin
  25. a:=q.x-p.x;
  26. b:=q.y-p.y;
  27. c:=-(q.x*q.x+q.y*q.y-p.x*p.x-p.y*p.y)/;
  28. d:=r.x-p.x;
  29. e:=r.y-p.y;
  30. f:=-(r.x*r.x+r.y*r.y-p.x*p.x-p.y*p.y)/;
  31. circumcenter.y:=(-c*d+f*a)/(b*d-e*a);
  32. circumcenter.x:=(-c*e+f*b)/(a*e-b*d);
  33. end;
  34.  
  35. function dis(a,b:point):extended;
  36. begin
  37. dis:=sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
  38. end;
  39.  
  40. procedure min_cover_circle;
  41. var i,j,k:longint;
  42. begin
  43. o:=v[];r:=;
  44. for i:= to n do
  45. begin
  46. if dis(v[i],o)>r+eps then
  47. begin
  48. o:=v[i];r:=;
  49. for j:= to i do
  50. if dis(v[j],o)>r+eps then
  51. begin
  52. o.x:=(v[i].x+v[j].x)/;
  53. o.y:=(v[i].y+v[j].y)/;
  54. r:=dis(v[j],o);
  55. for k:= to j do
  56. if dis(v[k],o)>r+eps then
  57. begin
  58. o:=circumcenter(v[i],v[j],v[k]);
  59. r:=dis(o,v[i]);
  60. end;
  61. end;
  62. end;
  63. end;
  64. end;
  65.  
  66. begin
  67. //assign(input,'amplifier20.in');reset(input);
  68. //assign(output,'amplifier20.out');rewrite(output);
  69. readln(n);
  70. for i:= to n do
  71. readln(v[i].x,v[i].y);
  72. readln(a);a:=a/*pi;
  73. readln(p);
  74. for i:= to n do
  75. rotate(i);
  76. if n= then
  77. begin
  78. writeln(dis(v[],v[])/::);
  79. //close(input);close(output);
  80. halt;
  81. end;
  82. min_cover_circle;
  83. writeln(r::);
  84. //close(input);close(output);
  85. end.

amplifier

其实说起来也不是很难,增量法我在考场居然也想到了,就是那时没想到可以以原点为中心,算法也写的有问题- -
来一发考场逗比错误代码,有空分析下错哪里了0 0

  1. program amplifier;
  2. uses math;
  3. const pi=3.141592653589;
  4. type vtype=record
  5. x,y:real;
  6. end;
  7. var n,p,i,n1,n2,n3:longint;
  8. xx,yy,xt,yt,a,aa,x0,y0:real;
  9. v:array[..] of vtype;
  10.  
  11. procedure cac(x1,y1,x2,y2,x3,y3:real);
  12. var a1,a2,b1,b2,c1,c2:real;
  13. begin
  14. if x1*y2+x2*y3+x3*y1-x3*y2-x2*y1-x1*y3= then exit;
  15. a1:=*(x1-x3);b1:=*p*p*(y1-y3);c1:=(x1*x1-x3*x3)+p*p*(y1*y1-y3*y3);
  16. a2:=*(x1-x2);b2:=*p*p*(y1-y2);c2:=(x1*x1-x2*x2)+p*p*(y1*y1-y2*y2);
  17. xt:=(b2*c1-b1*c2)/(a1*b2-a2*b1);
  18. yt:=(a1*c2-a2*c1)/(a1*b2-a2*b1);
  19. a:=sqrt(sqr(x1-xt)+p*p*sqr(y1-yt));
  20. end;
  21.  
  22. function ini(t:integer;x0,y0,a:real):boolean;
  23. var tt:real;
  24. begin
  25. tt:=sqr(v[t].x-x0)+p*p*sqr(v[t].y-y0);
  26. if tt<=a*a then exit(true) else exit(false);
  27. end;
  28.  
  29. procedure work2;
  30. begin
  31. xx:=(v[n1].x+v[n2].x)/;
  32. yy:=(v[n1].y+v[n2].y)/;
  33. a:=sqrt(sqr(v[n1].x-xx)+p*p*sqr(v[n1].y-yy));
  34. writeln((a/p)::);
  35. end;
  36.  
  37. function line(n1,n2,n3:integer):boolean;
  38. var x1,x2,x3,y1,y2,y3:real;
  39. begin
  40. x1:=v[n1].x;x2:=v[n2].x;x3:=v[n3].x;
  41. y1:=v[n1].y;y2:=v[n2].y;y3:=v[n3].y;
  42. if x1*y2+x2*y3+x3*y1-x3*y2-x2*y1-x1*y3= then exit(true) else exit(False);
  43. end;
  44.  
  45. procedure workline;
  46. begin
  47. if ((v[n1].x<v[n2].x) and (v[n2].x<v[n3].x)) or ((v[n3].x<v[n2].x) and (v[n2].x<v[n1].x)) then
  48. begin
  49. n2:=n3;n3:=n3+;exit;
  50. end;
  51. if ((v[n2].x<v[n1].x) and (v[n1].x<v[n3].x)) or ((v[n3].x<v[n1].x) and (v[n1].x<v[n2].x)) then
  52. begin
  53. n1:=n2;n2:=n3;n3:=n3+;exit;
  54. end;
  55. if ((v[n1].x<v[n3].x) and (v[n3].x<v[n2].x)) or ((v[n2].x<v[n3].x) and (v[n3].x<v[n1].x)) then
  56. begin
  57. n3:=n3+; exit;
  58. end;
  59. end;
  60.  
  61. begin
  62. assign(input,'amplifier.in');reset(input);
  63. assign(output,'amplifier.out');rewrite(output);
  64. readln(n);
  65. for i:= to n do
  66. readln(v[i].x,v[i].y);
  67. readln(a);readln(p);
  68. for i:= to n do
  69. begin
  70. x0:=v[i].x;y0:=v[i].y;
  71. v[i].x:=cos(-a/*pi)*x0-sin(-a/*pi)*y0;
  72. v[i].y:=sin(-a/*pi)*x0+cos(-a/*pi)*y0;
  73. end;
  74. v[n+].x:=;v[n+].y:=;
  75. if n= then writeln();
  76. if n= then
  77. begin
  78. n1:=;n2:=;
  79. work2;
  80. end;
  81. if n>= then
  82. begin
  83. n1:=;n2:=;n3:=;
  84. while (line(n1,n2,n3)) and (n3<>n+) do workline;
  85. if n3=n+ then
  86. begin
  87. work2;
  88. exit;
  89. end;
  90. cac(v[n1].x,v[n1].y,v[n2].x,v[n2].y,v[n3].x,v[n3].y);
  91. xx:=xt;yy:=yt;aa:=a;
  92. for i:=n3+ to n do
  93. begin
  94. if not ini(i,xx,yy,aa) then
  95. begin
  96. cac(v[n1].x,v[n1].y,v[n2].x,v[n2].y,v[i].x,v[i].y);
  97. if ini(n3,xt,yt,a) then
  98. begin
  99. n3:=i;xx:=xt;yy:=yt;aa:=a;continue;
  100. end;
  101. cac(v[n1].x,v[n1].y,v[i].x,v[i].y,v[n3].x,v[n3].y);
  102. if ini(n2,xt,yt,a) then
  103. begin
  104. n2:=n3;n3:=i;xx:=xt;yy:=yt;aa:=a;continue;
  105. end;
  106. cac(v[i].x,v[i].y,v[n2].x,v[n2].y,v[n3].x,v[n3].y);
  107. if ini(n1,xt,yt,a) then
  108. begin
  109. n1:=n2;n2:=n3;n3:=i;xx:=xt;yy:=yt;aa:=a;continue;
  110. end;
  111. end;
  112. end;
  113. writeln((a/p)::);
  114. end;
  115. close(input);close(output);
  116. end.

amplifier-wrong

[SHTSC 2014] 信号增幅仪的更多相关文章

  1. BZOJ 3564: [SHOI2014]信号增幅仪 最小圆覆盖

    3564: [SHOI2014]信号增幅仪 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=3564 Description 无线网络基站在 ...

  2. [LOJ 2190] 「SHOI2014」信号增幅仪

    [LOJ 2190] 「SHOI2014」信号增幅仪 链接 链接 题解 坐标系直到 \(x\) 轴与椭圆长轴平行 点的坐标变换用旋转公式就可以了 因为是椭圆,所以所有点横坐标除以 \(p\) 然后最小 ...

  3. 【bzoj3564】 [SHOI2014]信号增幅仪

    题目描述: 无线网络基站在理想状况下有效信号覆盖范围是个圆形.而无线基站的功耗与圆的半径的平方成正比. 现给出平面上若干网络用户的位置,请你选择一个合适的位置建设无线基站.... 就在你拿起键盘准备开 ...

  4. BZOJ3564 : [SHOI2014]信号增幅仪

    先把所有点绕原点逆时针旋转(360-a)度,再把所有点横坐标除以放大倍数p,最后用随机增量法求最小圆覆盖即可. 时间复杂度期望$O(n)$ #include<cstdio> #includ ...

  5. BZOJ 3564 信号增幅仪

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3564 题意:给出平面上n个点,画出一个椭圆,椭圆的长轴是短轴的p倍,且长轴的方向为x轴逆时 ...

  6. [BZOJ 3564] [SHOI2014] 信号增幅仪 【最小圆覆盖】

    题目链接:BZOJ - 3564 题目分析 求最小椭圆覆盖,题目给定了椭圆的长轴与 x 轴正方向的夹角,给定了椭圆长轴与短轴的比值. 那么先将所有点旋转一个角度,使椭圆长轴与 x 轴平行,再将所有点的 ...

  7. BZOJ3564 信号增幅仪

    http://www.lydsy.com/JudgeOnline/problem.php?id=3564 思路:先旋转坐标系,再缩进x坐标,把椭圆变成圆,然后做最小圆覆盖. 还有,为什么用srand( ...

  8. BZOJ 3564: [SHOI2014]信号增幅仪(随机增量法)

    如果是个圆的话好办,如果是拉成椭圆呢?直接压回去!!! 然后随机增量法就行了 CODE: #include<cstdio> #include<iostream> #includ ...

  9. 2018.10.15 bzoj3564: [SHOI2014]信号增幅仪(坐标处理+最小圆覆盖)

    传送门 省选考最小圆覆盖? 亦可赛艇(你们什么都没看见) 在大佬的引领下成功做了出来. 就是旋转坐标使椭圆的横轴跟xxx轴平行. 然后压缩横坐标使得其变成一个圆. 然后跑最小覆盖圆就可以了. 注意题目 ...

随机推荐

  1. kali安装java1.7

    1.先去这里下载你需要的版本 http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html 我 ...

  2. ajax局部刷新

    //5秒刷新一次 $(function () { setInterval(Refresh, 5000); }); //ajax局部刷新 function Refresh() { $.ajax({ ty ...

  3. Tutorial - Deferred Rendering Shadow Mapping 转

    http://www.codinglabs.net/tutorial_opengl_deferred_rendering_shadow_mapping.aspx Tutorial - Deferred ...

  4. c#_1:后台post请求

    1:aspx内容 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Push.as ...

  5. Linux环境部署(JDK/Tomcat/MySQL/证书)

    #################### 安装JDK1.7.x ####################下载JDK1.7版本的tar包(http://www.oracle.com/technetwor ...

  6. 执行Hadoop job提示SequenceFile doesn't work with GzipCodec without native-hadoop code的解决过程记录

    参照Hadoop.The.Definitive.Guide.4th的例子,执行SortDataPreprocessor作业时失败,输出的错误信息 SequenceFile doesn't work w ...

  7. AutoCAD Civil 3D 中缓和曲线的定义

    本文对AutoCAD Civil 3D中缓和曲线的定义进行了整理. 原英文网页如下: https://knowledge.autodesk.com/support/autocad-civil-3d/l ...

  8. Convert Sorted List to Binary Search Tree [LeetCode]

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  9. 初识ReactJs(一)

    React的开发背景 ReactJS官网地址:http://facebook.github.io/react/ Github地址:https://github.com/facebook/react J ...

  10. Centos 6.5 把自带python 2.6.6, 升级到 2.7

    http://blog.csdn.net/jcjc918/article/details/11022345