Created
October 11, 2011 01:09
-
-
Save fatihpense/1277022 to your computer and use it in GitHub Desktop.
Petek problemi çözümü
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.karrels.org/Ed/ACM/99/prob_a.html | |
print "melaba dunya" | |
#koor={1:(0,0), 2:(0,-1),3:(-1,-0.5),4:(-1,0.5),5:(0,1),6:(1,0.5),7:(1,-0.5)} | |
koor={1:(0,0.0), 2:(0,-1.0)} | |
dolu={'0,0.0':1,'0,-1.0':2} | |
#1 (0 , +1 | |
#2 (-1 , +0.5 | |
#3 (-1 , -0.5 | |
#4 (0 , -1 | |
#5 (+1 , -0.5 | |
#6 (+1 , +0.5 | |
def hareket(no,x, y): | |
if no>6: | |
no=no%6 | |
if no==0: #yukari cik | |
y=y+1 | |
if no==1: | |
x=x-1 | |
y=y+0.5 | |
if no==2: | |
x=x-1 | |
y=y-0.5 | |
if no==3: | |
y=y-1 | |
if no==4: | |
x=x+1 | |
y=y-0.5 | |
if no==5: | |
x=x+1 | |
y=y+0.5 | |
return (x,y) | |
# h=h+3+1 | |
# if h>6: | |
# h=h-6 | |
#print koor[5][1] | |
#print no['0,0'] | |
#print '%d,%f'%(tuple[0], round(tuple[1],1)) | |
#print '-1,0.5' in dolu | |
#print '%s,%s'%(str(tuple[0]),str(tuple[1])) in dolu | |
h=3 #son hareketin yonu | |
n=2 #hangi aridayiz | |
while n<100: | |
n=n+1 #ariyi arttir | |
h=h+3+1 #son harekete ters kareye bakip bir soldan denemeye basla | |
dene=True | |
while dene== True: | |
h=h%6 | |
adim_sonrasi= hareket(h,koor[n-1][0],koor[n-1][1]) | |
if '%s,%s'%(str(adim_sonrasi[0]),str(adim_sonrasi[1])) in dolu: | |
print '%s,%s ...dolu'%(str(adim_sonrasi[0]),str(adim_sonrasi[1])) | |
if not '%s,%s'%(str(adim_sonrasi[0]),str(adim_sonrasi[1])) in dolu: | |
#n+1 i belirle | |
print "adim atilacak.. %d. ARI icin (h=%d)"%(n,h) | |
koor[n]=(adim_sonrasi[0],adim_sonrasi[1]) | |
dolu['%s,%s'%(str(adim_sonrasi[0]),str(adim_sonrasi[1]))]=n | |
print "atildi! -> %s"%(str(koor[n])) | |
dene=False | |
h=h+1 | |
def adim_say(x1,y1,x2,y2): | |
adim=0 | |
xfark=abs(x2-x1) | |
yfark=abs(y2-y1) | |
while yfark>0 and xfark>0: | |
yfark=yfark-0.5 | |
xfark=xfark-1 | |
adim=adim+1 | |
while yfark>0: | |
yfark=yfark-1 | |
adim=adim+1 | |
while xfark>0: | |
xfark=xfark-1 | |
adim=adim+1 | |
return adim | |
#70. ari ve 57. ari arasindaki adimlar | |
print adim_say(koor[70][0],koor[70][1],koor[57][0],koor[57][1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment