三米
大哥,怎么做
先记下来机器模拟一下再回来
<P>在半径为1.5,一步走1的时候结果是3.528左右,还是比较稳定,大概正负0.003,其他参数的时候没算</P>
<P>这段程序可以近似模拟,如有错误欢迎指正<IMG src="http://www.shumo.com/bbs/Skins/Default/emot/em20.gif"></P>
<P>#include<iostream><br>#include<cstdlib><br>#include<ctime><br>#include<cmath><br>using namespace std;<br>bool IsOut(const double x,const double y);<br>const double R=1.5;<br>const double step=1;<br>const long MAX=10000000;<br>void main()<br>{<br>double x=0; //初始位置<br>double y=0;<br>double new_x;<br>double new_y;<br>double alpha;<br>double count=0;<br>srand(time(0));<br>for(int i=0;i<MAX;i++)<br>{<br><br>for(;;)<br>{<br> if(!IsOut(x,y))<br> {<br> alpha=(double(rand())/RAND_MAX)*361;<br> new_x=step*cos(alpha)+x;<br> new_y=step*sin(alpha)+y;<br> x=new_x;<br> y=new_y;<br> count++;<br> }<br> else<br> break;<br>}<br>x=0;<br>y=0;<br>}<br>cout<<"平均需要走"<<count/MAX<<"步"<<endl;<br>}<br>bool IsOut(const double x,const double y)<br>{<br>if((x*x+y*y)<=R*R)<br>return false;<br>else<br>return true;<br>}</P>
[此贴子已经被作者于2005-10-3 12:29:32编辑过]
上面是求的平均值 取整数就是4
[此贴子已经被作者于2005-10-3 12:29:58编辑过]
难!!!
至少多过3个钟,但是没有规律走,麻烦
<P>可以走成正六边形,这个时候永远也走不出去。</P>
<P>很多时候走不出去。</P>
有难度!
收录中.......