解题思路:
借鉴了https://www.cnblogs.com/EchoZQN/p/14829144.html的做法
注意事项:
参考代码:
k = int(input())
x1,y1 = map(int,input().split())
x2,y2 = map(int,input().split())
def dg(n,x,y):
if n == 0: return 1
m = 3**n #k阶的边长
cnt = (3**(2*n))//9 #k-1阶 起点到终点的距离
if x < m//3:
if y<m//3: #区域一
return dg(n-1,x,y)
elif y<m*2//3: #区域二
return cnt + dg(n-1,m//3-1-x,y-m//3) #注意将起点重置(看起点之后变化方向)
else: #区域三
return cnt*2 + dg(n-1,x,y-2*m//3)
elif x<m*2//3:
if y<m//3:
return cnt*5+dg(n-1,x-m//3,m//3-1-y)
elif y<m*2//3:
return cnt*4 + dg(n-1,m*2//3-1-x,m*2//3-1-y)
else:
return cnt*3 + dg(n-1,x-m//3,m-1-y)
else:
if y<m//3:
return cnt*6+dg(n-1,x-m*2//3,y)
elif y<m*2//3:
return cnt*7 + dg(n-1,m-1-x,y-m//3)
else:
return cnt*8 + dg(n-1,x-m*2//3,y-m*2//3)
res = abs(dg(k,x1,y1)-dg(k,x2,y2))
print(res)
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:724 |
【蟠桃记】 (C语言代码)浏览:648 |
C语言训练-列出最简真分数序列* (C语言代码)浏览:603 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:504 |
C语言程序设计教程(第三版)课后习题6.3 (C++代码)浏览:950 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:533 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)from DQM浏览:653 |
蛇行矩阵 (C语言代码)浏览:498 |
单词个数统计 (C语言代码)浏览:1009 |
简单的a+b (C语言代码)浏览:645 |