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

主要参考以下
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] 信号增幅仪的更多相关文章

  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. 【干货】微信场景之H5页面制作免费工具大集合

    营销代有手段出,各领风骚数百天.要说现在哪些营销方式最能传播,屡屡刷爆朋友圈的H5页面肯定就是首当其冲的,提到H5页面,就立马想到"围住神经猫",上线微信朋友圈3天的时间便创造了用 ...

  2. PHP中的逻辑运算符的优先级

    在三元运算中(expr1)?(expr2):(expr3); and,or,xor的优先级要小于三元运算符,所以需要添加括号例:如果$a为true,$b为fals,$a and $b?"tr ...

  3. 承接unity外包:2016年VR产业八大发展趋势

    在上周进行的2016年全球游戏开发者大会(GDC)期间,虚拟现实技术是一个重要议题.英文科技媒体VentureBeat近日刊出了一篇文章,对2016年VR产业的发展趋势进行了预测.游戏陀螺对文章分享的 ...

  4. iframe布局

    代码如下: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF ...

  5. 疑惑的 java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()L

    在MAVEN项目里面,在整合spring和mybatis在执行数据库操作的时候报出了: java.lang.AbstractMethodError: org.mybatis.spring.transa ...

  6. led灯的翻转函数

    定义: uint8_t led1_val; void LED1(uint8_t* val){ *val =!(*val); if( *val == 0x00 ) HAL_GPIO_WritePin ( ...

  7. hibernate 和 myBatis 比较

    Hibernate与 MyBatis的比较 第一章     Hibernate与MyBatis Hibernate 是当前最流行的O/R mapping框架,它出身于sf.net,现在已经成为Jbos ...

  8. centos中安装字体

    转载自:http://blog.csdn.net/wlwlwlwl015/article/details/51482065 在使用phantomjs做自动化网页截图时,发现截图都没有文字.最后好久才发 ...

  9. swift_简单值 | 元祖 | 流程控制 | 字符串 | 集合

    //: Playground - noun: a place where people can play import Cocoa var str = "Hello, playground& ...

  10. (42) Aeroo 模板实战

    用writer设计一个采购单的模板 我用的是libreoffice 5.2.x 对于这个表格是通过工具栏上的插入指定的表格行和列完成,然后排版 对于单号po00001 这这样插入的 这样就完成一个订单 ...