这是一个艾博挑战。你的目标是尽快达到2011年的数字,或者尽可能接近它。
(row, col),左上角为(0, 0).14932875921047
60438969014654
56398659108239
90862084187569
94876198569386
14897356029523Start: (3, 7)
+4=4
*9=36
*9=324
*6=1944
+9=1953
+8=1961
+8=1969
+9=1978
+6=1984
+8=1992
+8=2000
+8=2008
+4=2012
-1=2011
Strokes: 14
Score: 14
14932875921047
6043....014654
563..65.108239
90..208.187569
94.76198569386
...97356029523Start: (3, 7)
+4=4 *9=36 *9=324 *6=1944 +9=1953 +8=1961 +8=1969 +9=1978 +6=1984 +8=1992 +8=2000 +8=2008 +4=2012 -1=2011
Strokes: 14 Score: 140346092836
1986249812
3568086343
5509828197
4612486355
3025745681
7685047124
2098745313Start: (4, 7)
+3=3
*6=18
*5=90
+7=97
*5=485
*4=1940
+7=1947
+8=1955
+9=1964
+8=1972
+6=1978
+7=1985
+3=1988
+4=1992
+5=1997
+5=2002
+5=2007
+3=2010
+1=2011
Strokes: 19
Score: 19
0346092836
.986249812
..68086343
..09828197
.61248..55
.02574.681
...504.124
20.....3139876
5432
1098
7654
3210Start: (2, 2)
+9=9
*8=72
*4=288
*5=1440
+6=1446
+7=1453
+3=1456
+2=1458
+1=1459
Strokes: 9
Score: 561
9876
5432
10..
....
....39857205
74493859
02175092
54239112
39209358
34568905Start: (0, 0)
+3=3
*7=21
*4=84
*4=336
-1=335
*2=670
/3=(670/3)
*9=2010
+1=2011
.9857205
...93859
02.75092
54....12
39209358
34568905不幸的是,只有两名选手,但我会公布结果。
#1 - Howard (1881)
#2 - Gareth (5442)课程的前半部分由大致“正常”的洞组成,大部分是随机产生的。下半场更有挑战性,因为洞里有更多的“沙坑”(特别是0)。
**Howard**
01) 5 - 5
02) 5 - 5
03) 6 - 6
04) 6 - 7
05) 6 - 7
06) 6 - 6
07) 5 - 5
08) 5 - 5
09) 6 - 6
10) 9 - 10
11) 5 - 8
12) 8 - 8
13) 6 - 7
14) 8 - 9
15) 7 - 12
16) 20 - 1665
17) 29 - 66
18) 30 - 44
Front 9) 52
Back 9) 1829
Full 18) 1881
**Gareth**
01) 9 - 10
02) 33 - 173
03) 8 - 8
04) 11 - 16
05) 7 - 84
06) 17 - 17
07) 9 - 10
08) 8 - 8
09) 15 - 15
10) 16 - 16
11) 12 - 32
12) 18 - 164
13) 34 - 335
14) 10 - 10
15) 26 - 447
16) 78 - 78
17) 1 - 2010
18) 1 - 2009
Front 9) 341
Back 9) 5101
Full 18) 5442使用的课程可以在巴斯丁上找到。
@Howard:由于对ideone的限制,我以较低的路径数运行了您的程序。如果您的完整版本给出了显著不同的结果,让我知道的分数和程序的相对运行时间。
发布于 2011-08-28 18:33:49
Why-Not-Try-It-The-Easy-Way-Approach -
发布于 2011-08-29 14:36:36
object Main
{
def main(args:Array[String])
{
var input=io.Source.stdin.getLines.toArray
while(!input.isEmpty)
{
var hole=input.takeWhile(_!="").map(_.map(x=>Integer.parseInt(x.toString)).toArray).toArray
input=input.dropWhile(_!="")
if(!input.isEmpty)
input=input.tail
var (height,width)=(hole.size,hole.head.size)
var bestscore=10000000
var bestrunoutput=""
var currentval=0
var output=""
var exit=false
var c:Array[Array[Int]]=Array(Array(0))
var(steps,xnow,ynow)=(0,0,0)
def getNeighbours(x:Int,y:Int,c:Array[Array[Int]]):Array[(Int,Int,Int)]=
(for(a<- -1 to 1;b<- -1 to 1;if(Math.abs(a)!=Math.abs(b) && x+b>=0 && x+b<width && y+a>=0 && y+a<height)) yield (c(y+a)(x+b),x+b,y+a)).toArray.sortBy(_._1).reverse
for(y<-0 until height;x<-0 until width)
{
c=hole.map(_.clone)
exit=false
steps=0
xnow=x
ynow=y
currentval=c(ynow)(xnow)
output="Start: ("+y+","+x+")\n+"+currentval+"="+currentval+"\n"
while(!exit)
{
var neighbours=getNeighbours(xnow,ynow,c)
while(neighbours.size>0 && (neighbours.head._1*currentval>2011 || neighbours.head._1<2))
neighbours=neighbours.drop(1)
if(neighbours.size==0)
{
neighbours=getNeighbours(xnow,ynow,c)
while(neighbours.size>0 && (neighbours.head._1+currentval>2011 || neighbours.head._1==0))
neighbours=neighbours.drop(1)
if(neighbours.size==0)
{
exit=true
}
else
{
currentval+=neighbours.head._1
c(ynow)(xnow)=0
output+="+"+neighbours.head._1+"="+currentval+"\n"
}
}
else
{
currentval*=neighbours.head._1
c(ynow)(xnow)=0
output+="*"+neighbours.head._1+"="+currentval+"\n"
}
if(!exit)
{
xnow=neighbours.head._2
ynow=neighbours.head._3
}
steps+=1
}
output+="Strokes: "+steps+"\nScore: "+(steps+2011-currentval)+"\n"
if(steps+2011-currentval<bestscore)
{
bestscore=steps+2011-currentval
bestrunoutput=output
}
}
println(bestrunoutput)
}
println
}
}我把它整理了一下,修正了一个错误,这个bug让相同的数字不止一次地被用于添加,并且我已经满足了(我以前没有发现)以多个洞作为输入的要求。
算法相当简单:
For every possible start point:
Find the highest value neighbour and try multiplying it
If it's too high
Try the next highest neighbour
If there are no more neighbours
Find the highest value neighbour and try adding it
If it's too high
Try the next highest neighbour
If there are no more neighbours
End this attempt and calculate the score
Print out the attempt with the best score在ideone.com中运行:
14932875921047
60438969014654
56398659108239
90862084187569
94876198569386
14897356029523
0346092836
1986249812
3568086343
5509828197
4612486355
3025745681
7685047124
2098745313
9876
5432
1098
7654
3210
39857205
74493859
02175092
54239112
39209358
34568905Start: (0,3)
+3=3
*9=27
*4=108
*3=324
*6=1944
+5=1949
+9=1958
+9=1967
+4=1971
+8=1979
+8=1987
+9=1996
+7=2003
+6=2009
+2=2011
Strokes: 15
Score: 15
Start: (6,6)
+7=7
*5=35
*4=140
*7=980
+8=988
+9=997
+8=1005
*2=2010
+1=2011
Strokes: 9
Score: 9
Start: (4,0)
+3=3
*7=21
*6=126
*5=630
+9=639
*3=1917
+7=1924
+8=1932
+9=1941
+5=1946
+4=1950
Strokes: 11
Score: 72
Start: (4,5)
+3=3
*9=27
*8=216
*9=1944
+9=1953
+5=1958
+7=1965
+9=1974
+5=1979
+8=1987
+9=1996
+4=2000
+7=2007
+3=2010
Strokes: 14
Score: 15和霍华德的老虎伍兹相比,我的周末高尔夫选手一定很满足。:-)
https://codegolf.stackexchange.com/questions/3581
复制相似问题