[SHTSC 2014] 信号增幅仪
最小覆盖圆算法。看着题解半蒙半抄的搞过去了…
主要参考以下
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)
- program amplifier;
- uses math;
- type point=record
- x,y:extended;
- end;
- const maxn=;
- pi=3.14159265358979;
- eps=0.00000001;
- var n,i,p:longint;
- a,r:extended;
- o:point;
- v:array[..maxn+] of point;
- procedure rotate(i:longint);
- var x,y:extended;
- begin
- x:=v[i].x*cos(-a)-v[i].y*sin(-a);
- y:=v[i].x*sin(-a)+v[i].y*cos(-a);
- v[i].x:=x/p;
- v[i].y:=y;
- end;
- function circumcenter(p,q,r:point):point;
- var a,b,c,d,e,f:extended;
- begin
- a:=q.x-p.x;
- b:=q.y-p.y;
- c:=-(q.x*q.x+q.y*q.y-p.x*p.x-p.y*p.y)/;
- d:=r.x-p.x;
- e:=r.y-p.y;
- f:=-(r.x*r.x+r.y*r.y-p.x*p.x-p.y*p.y)/;
- circumcenter.y:=(-c*d+f*a)/(b*d-e*a);
- circumcenter.x:=(-c*e+f*b)/(a*e-b*d);
- end;
- function dis(a,b:point):extended;
- begin
- dis:=sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
- end;
- procedure min_cover_circle;
- var i,j,k:longint;
- begin
- o:=v[];r:=;
- for i:= to n do
- begin
- if dis(v[i],o)>r+eps then
- begin
- o:=v[i];r:=;
- for j:= to i do
- if dis(v[j],o)>r+eps then
- begin
- o.x:=(v[i].x+v[j].x)/;
- o.y:=(v[i].y+v[j].y)/;
- r:=dis(v[j],o);
- for k:= to j do
- if dis(v[k],o)>r+eps then
- begin
- o:=circumcenter(v[i],v[j],v[k]);
- r:=dis(o,v[i]);
- end;
- end;
- end;
- end;
- end;
- begin
- //assign(input,'amplifier20.in');reset(input);
- //assign(output,'amplifier20.out');rewrite(output);
- readln(n);
- for i:= to n do
- readln(v[i].x,v[i].y);
- readln(a);a:=a/*pi;
- readln(p);
- for i:= to n do
- rotate(i);
- if n= then
- begin
- writeln(dis(v[],v[])/::);
- //close(input);close(output);
- halt;
- end;
- min_cover_circle;
- writeln(r::);
- //close(input);close(output);
- end.
amplifier
其实说起来也不是很难,增量法我在考场居然也想到了,就是那时没想到可以以原点为中心,算法也写的有问题- -
来一发考场逗比错误代码,有空分析下错哪里了0 0
- program amplifier;
- uses math;
- const pi=3.141592653589;
- type vtype=record
- x,y:real;
- end;
- var n,p,i,n1,n2,n3:longint;
- xx,yy,xt,yt,a,aa,x0,y0:real;
- v:array[..] of vtype;
- procedure cac(x1,y1,x2,y2,x3,y3:real);
- var a1,a2,b1,b2,c1,c2:real;
- begin
- if x1*y2+x2*y3+x3*y1-x3*y2-x2*y1-x1*y3= then exit;
- a1:=*(x1-x3);b1:=*p*p*(y1-y3);c1:=(x1*x1-x3*x3)+p*p*(y1*y1-y3*y3);
- a2:=*(x1-x2);b2:=*p*p*(y1-y2);c2:=(x1*x1-x2*x2)+p*p*(y1*y1-y2*y2);
- xt:=(b2*c1-b1*c2)/(a1*b2-a2*b1);
- yt:=(a1*c2-a2*c1)/(a1*b2-a2*b1);
- a:=sqrt(sqr(x1-xt)+p*p*sqr(y1-yt));
- end;
- function ini(t:integer;x0,y0,a:real):boolean;
- var tt:real;
- begin
- tt:=sqr(v[t].x-x0)+p*p*sqr(v[t].y-y0);
- if tt<=a*a then exit(true) else exit(false);
- end;
- procedure work2;
- begin
- xx:=(v[n1].x+v[n2].x)/;
- yy:=(v[n1].y+v[n2].y)/;
- a:=sqrt(sqr(v[n1].x-xx)+p*p*sqr(v[n1].y-yy));
- writeln((a/p)::);
- end;
- function line(n1,n2,n3:integer):boolean;
- var x1,x2,x3,y1,y2,y3:real;
- begin
- x1:=v[n1].x;x2:=v[n2].x;x3:=v[n3].x;
- y1:=v[n1].y;y2:=v[n2].y;y3:=v[n3].y;
- if x1*y2+x2*y3+x3*y1-x3*y2-x2*y1-x1*y3= then exit(true) else exit(False);
- end;
- procedure workline;
- begin
- 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
- begin
- n2:=n3;n3:=n3+;exit;
- end;
- 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
- begin
- n1:=n2;n2:=n3;n3:=n3+;exit;
- end;
- 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
- begin
- n3:=n3+; exit;
- end;
- end;
- begin
- assign(input,'amplifier.in');reset(input);
- assign(output,'amplifier.out');rewrite(output);
- readln(n);
- for i:= to n do
- readln(v[i].x,v[i].y);
- readln(a);readln(p);
- for i:= to n do
- begin
- x0:=v[i].x;y0:=v[i].y;
- v[i].x:=cos(-a/*pi)*x0-sin(-a/*pi)*y0;
- v[i].y:=sin(-a/*pi)*x0+cos(-a/*pi)*y0;
- end;
- v[n+].x:=;v[n+].y:=;
- if n= then writeln();
- if n= then
- begin
- n1:=;n2:=;
- work2;
- end;
- if n>= then
- begin
- n1:=;n2:=;n3:=;
- while (line(n1,n2,n3)) and (n3<>n+) do workline;
- if n3=n+ then
- begin
- work2;
- exit;
- end;
- cac(v[n1].x,v[n1].y,v[n2].x,v[n2].y,v[n3].x,v[n3].y);
- xx:=xt;yy:=yt;aa:=a;
- for i:=n3+ to n do
- begin
- if not ini(i,xx,yy,aa) then
- begin
- cac(v[n1].x,v[n1].y,v[n2].x,v[n2].y,v[i].x,v[i].y);
- if ini(n3,xt,yt,a) then
- begin
- n3:=i;xx:=xt;yy:=yt;aa:=a;continue;
- end;
- cac(v[n1].x,v[n1].y,v[i].x,v[i].y,v[n3].x,v[n3].y);
- if ini(n2,xt,yt,a) then
- begin
- n2:=n3;n3:=i;xx:=xt;yy:=yt;aa:=a;continue;
- end;
- cac(v[i].x,v[i].y,v[n2].x,v[n2].y,v[n3].x,v[n3].y);
- if ini(n1,xt,yt,a) then
- begin
- n1:=n2;n2:=n3;n3:=i;xx:=xt;yy:=yt;aa:=a;continue;
- end;
- end;
- end;
- writeln((a/p)::);
- end;
- close(input);close(output);
- end.
amplifier-wrong
[SHTSC 2014] 信号增幅仪的更多相关文章
- BZOJ 3564: [SHOI2014]信号增幅仪 最小圆覆盖
3564: [SHOI2014]信号增幅仪 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=3564 Description 无线网络基站在 ...
- [LOJ 2190] 「SHOI2014」信号增幅仪
[LOJ 2190] 「SHOI2014」信号增幅仪 链接 链接 题解 坐标系直到 \(x\) 轴与椭圆长轴平行 点的坐标变换用旋转公式就可以了 因为是椭圆,所以所有点横坐标除以 \(p\) 然后最小 ...
- 【bzoj3564】 [SHOI2014]信号增幅仪
题目描述: 无线网络基站在理想状况下有效信号覆盖范围是个圆形.而无线基站的功耗与圆的半径的平方成正比. 现给出平面上若干网络用户的位置,请你选择一个合适的位置建设无线基站.... 就在你拿起键盘准备开 ...
- BZOJ3564 : [SHOI2014]信号增幅仪
先把所有点绕原点逆时针旋转(360-a)度,再把所有点横坐标除以放大倍数p,最后用随机增量法求最小圆覆盖即可. 时间复杂度期望$O(n)$ #include<cstdio> #includ ...
- BZOJ 3564 信号增幅仪
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3564 题意:给出平面上n个点,画出一个椭圆,椭圆的长轴是短轴的p倍,且长轴的方向为x轴逆时 ...
- [BZOJ 3564] [SHOI2014] 信号增幅仪 【最小圆覆盖】
题目链接:BZOJ - 3564 题目分析 求最小椭圆覆盖,题目给定了椭圆的长轴与 x 轴正方向的夹角,给定了椭圆长轴与短轴的比值. 那么先将所有点旋转一个角度,使椭圆长轴与 x 轴平行,再将所有点的 ...
- BZOJ3564 信号增幅仪
http://www.lydsy.com/JudgeOnline/problem.php?id=3564 思路:先旋转坐标系,再缩进x坐标,把椭圆变成圆,然后做最小圆覆盖. 还有,为什么用srand( ...
- BZOJ 3564: [SHOI2014]信号增幅仪(随机增量法)
如果是个圆的话好办,如果是拉成椭圆呢?直接压回去!!! 然后随机增量法就行了 CODE: #include<cstdio> #include<iostream> #includ ...
- 2018.10.15 bzoj3564: [SHOI2014]信号增幅仪(坐标处理+最小圆覆盖)
传送门 省选考最小圆覆盖? 亦可赛艇(你们什么都没看见) 在大佬的引领下成功做了出来. 就是旋转坐标使椭圆的横轴跟xxx轴平行. 然后压缩横坐标使得其变成一个圆. 然后跑最小覆盖圆就可以了. 注意题目 ...
随机推荐
- kali安装java1.7
1.先去这里下载你需要的版本 http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html 我 ...
- ajax局部刷新
//5秒刷新一次 $(function () { setInterval(Refresh, 5000); }); //ajax局部刷新 function Refresh() { $.ajax({ ty ...
- Tutorial - Deferred Rendering Shadow Mapping 转
http://www.codinglabs.net/tutorial_opengl_deferred_rendering_shadow_mapping.aspx Tutorial - Deferred ...
- c#_1:后台post请求
1:aspx内容 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Push.as ...
- Linux环境部署(JDK/Tomcat/MySQL/证书)
#################### 安装JDK1.7.x ####################下载JDK1.7版本的tar包(http://www.oracle.com/technetwor ...
- 执行Hadoop job提示SequenceFile doesn't work with GzipCodec without native-hadoop code的解决过程记录
参照Hadoop.The.Definitive.Guide.4th的例子,执行SortDataPreprocessor作业时失败,输出的错误信息 SequenceFile doesn't work w ...
- AutoCAD Civil 3D 中缓和曲线的定义
本文对AutoCAD Civil 3D中缓和曲线的定义进行了整理. 原英文网页如下: https://knowledge.autodesk.com/support/autocad-civil-3d/l ...
- 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 ...
- 初识ReactJs(一)
React的开发背景 ReactJS官网地址:http://facebook.github.io/react/ Github地址:https://github.com/facebook/react J ...
- Centos 6.5 把自带python 2.6.6, 升级到 2.7
http://blog.csdn.net/jcjc918/article/details/11022345