|
发表于 2011-2-19 02:48:52
|
显示全部楼层
偶然看到这个帖子哈,很感兴趣,不知道算不算挖坟啊?
自己做了一下,有不足之处望海涵,jass不会,用的java
public class main
{
static long starttime=System.currentTimeMillis();
static int speed=3,startlocation=255,direction=0;
public static void main(String args[])
{
System.out.println("program start");
function();
}
private static void bomb(int speed2,int startlocation2,int direct)
{
int location;
int time=(int)((System.currentTimeMillis()-starttime)*0.001);
int bomblocation;
int road=(int)((System.currentTimeMillis()-starttime)*0.001);
if(direct==1)
{
bomblocation=startlocation2+time*speed2;
}
else
{
bomblocation=startlocation2-time*speed2;
}
if(direction==1)
{
location=startlocation+speed*time;
}
else
{
location=startlocation-speed*time;
}
try
{
Thread.currentThread().sleep(1000);
}
catch(Exception e)
{
}
System.out.println("当前假定速度为"+speed2+"起始位置为"+startlocation2+"方向为"+direct);
System.out.println("炸弹扔在"+bomblocation+"处"+"潜艇在"+location+"处"+"当前运行了"+time);
if(bomblocation==location)
{
System.out.println("done");
System.exit(0);
}
}
private static void function()
{
int speed=1;
int startlocation=0;
int temp=0;
while(true)
{
bomb(speed,startlocation,1);
bomb(speed,-startlocation,1);
bomb(speed,startlocation,0);
bomb(speed,-startlocation,0);
if(temp==0)
{
speed++;
temp=1;
}
else
{
startlocation++;
temp=0;
}
}
}
}
------------------------------------------
关于此算法有穷性的简单证明:
假设潜水艇速度为v,起始位置为n,位置为一布尔数
设function为基本操作单位,则算法执行v*n*2个基本操作.
又因v,n都wei确定整数,则v*n*2必然为一整数;
故此算法必然可在有限基本操作单位内完成.
数学很烂,证明更烂,不知道有什么地方出错了还请大家多多指教. |
|