空中飞猴 题解 暴力
来源:互联网 发布:淘宝联盟东西是真的吗 编辑:程序博客网 时间:2024/04/29 19:32
题目描述
马戏团里新来了一只很特别的小猴子,不仅长得漂亮,还很聪明。自从它来到马戏团之后,“空中飞猴”成了马戏团里的保留节目,慕名观看的人络绎不绝。
“空中飞猴”表演开始时,空中架着两根长长的钢丝。峰峰在其中一根上,它的目标是到达另一个根钢丝上,必须在爬行一定距离后纵身一跃,直接跳到另一根钢丝的某个位置。由于它的速度非常快,它的运动轨迹可以近似的看成一条直线段。为了不让自己太危险,希望自己的跳跃距离尽量短,而为了不让观众等得太不耐烦,它在钢丝上的爬行距离不能超过d。
请你求出在爬行距离不超过d的情况下,峰峰的跳跃距离最短是多少?
....据说三分可做?并没有得到证明= =...
....据说计算几何?然而蒟蒻并不会= =...
虽然暴力的时间复杂度很迷,正确性很迷,和乱搞是没有什么区别的,但是居然就这么过了....= =
果然暴力出奇迹不是骗人的。
最短的跳跃距离,就是从小猴所在钢丝l1上,找到一点,然后再从另一根钢丝l2上,找到该点最短的落点,然后求个dis就行...
因为它都是实数,蒟蒻并不知道怎么枚举...
看了一下标程,设了一个delta[i]数组,delta[i]=(1/4)^(-i),1<=i<=14
然后以delta[i]为枚举步长乱搞...并不知道为什么
对于在l1上的起点now的要求:
(1)dis(小猴起点,now)<=d
(2)now在线段l1上,即到两端点的距离都小于等于长度
对于l2上落点arrive的要求:
(1)min(dis(now,arrive))
(2)arrive在线段l2上,即到两端点距离小于等于长度
type rec=record x,y,z:real;end;var p1,p2,p3,p4,p5 :rec; ans,len1,len2,d :real; now,mid :rec; change_foot :rec; v1,v2 :rec; t :rec; cas :longint; i :longint; delta :array[0..14] of real;function plus(a,b:rec):rec;var c:rec;begin c.x:=a.x+b.x; c.y:=a.y+b.y; c.z:=a.z+b.z; exit(c);end;function mul(a:rec;b:real):rec;var c:rec;begin c.x:=a.x*b; c.y:=a.y*b; c.z:=a.z*b; exit(c);end;function sub(a,b:rec):rec;var c:rec;begin c.x:=a.x-b.x; c.y:=a.y-b.y; c.z:=a.z-b.z; exit(c);end;function dis(a,b:rec):real;begin exit( sqrt( sqr(a.x-b.x) + sqr(a.y-b.y) + sqr(a.z-b.z) ) );end;function work(pos:rec):real;var arrive,tt:rec; ans:real; i:longint;begin arrive:=mid; ans:=dis(arrive,pos); for i:=1 to 14 do begin tt:=mul(v2,delta[i]); while (dis(plus(arrive,tt),pos)<ans) and (dis(plus(arrive,tt),mid)<=len2/2) do begin arrive:=plus(arrive,tt); ans:=dis(pos,arrive); end; while (dis(pos,sub(arrive,tt))<ans) and (dis(sub(arrive,tt),mid)<=len2/2) do begin arrive:=sub(arrive,tt); ans:=dis(pos,arrive); end; end; exit(ans);end;procedure check(delta:rec);var tt:rec; tans:double;begin while true do begin tt:=plus(delta,now); if (dis(tt,p5)>d) then break; if (dis(tt,p1)>len1) then break; if (dis(tt,p2)>len1) then break; tans:=work(tt); if tans<ans then begin ans:=tans; now:=tt; end else break; end;end;begin //assign(input,'mky.in');reset(input); //assign(output,'mky.out');rewrite(output); delta[0]:=1; for i:=1 to 14 do delta[i]:=1/4*delta[i-1]; read(cas); while (cas>0) do begin dec(cas); read(p1.x,p1.y,p1.z,p2.x,p2.y,p2.z,p3.x,p3.y,p3.z,p4.x,p4.y,p4.z,p5.x,p5.y,p5.z,d); len1:=dis(p1,p2); len2:=dis(p3,p4); v1:=sub(p2,p1); v2:=sub(p4,p3); mid:=mul(plus(p3,p4),0.5); ans:=work(p5); now:=p5; // for i:=1 to 14 do begin change_foot:=mul(v1,delta[i]); check(change_foot); change_foot:=mul(v1,-delta[i]); check(change_foot); end; writeln(ans:0:3); readln; end; //close(input);close(output);end.——by Eirlys
0 0
- 空中飞猴 题解 暴力
- 地上走,空中飞
- 【神暴力】三元环题解
- 化装晚会(costume)暴力题解
- 空中上网,且飞且互联
- 水题~HDU 1303 Double 题解+直接暴力
- 黑马程序员_java基础加强11_空中网题解_自己做的答案
- 黑马程序员_java基础加强12_空中网题解_老师解答
- 空中财富
- 空中打击
- 空中接口
- 空中花园
- 空中下载
- 空中键盘
- 【BZOJ】【P4292】【PA2015】【Równanie】【题解】【暴力】
- Codeforces Round #323 (Div. 2) ABC题解(全是暴力)
- 【概率与期望】【暴力搜索】[Codeforces#621]题解+总结
- Codeforces Round #344 (Div. 2) A 题题解 (暴力)
- cura 3d打印底座防止翘边好方法 的 升级知识点
- 如何让进程杀不死(2)
- 学习C++ (运算符和表达式)
- 为什么我们要用线程池
- 早实现早享受
- 空中飞猴 题解 暴力
- iOS开发-多线程简单介绍
- 深度增强学习前沿算法思想
- 让div里面标签居中的方法
- python第二十四天学习记录
- 310. Minimum Height Trees
- 2017年的计划
- PAT-B 1013. 数素数 (20)
- window10 搭建vue+IIS部署(最详细步骤)