国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python3解決棋盤覆蓋問題的方法示例

Python3解決棋盤覆蓋問題的方法示例

2020-12-22 00:54littlethunder Python

這篇文章主要介紹了Python3解決棋盤覆蓋問題的方法,簡單描述了棋盤覆蓋問題的概念、原理及Python相關操作技巧,需要的朋友可以參考下

本文實例講述了Python3解決棋盤覆蓋問題的方法。分享給大家供大家參考,具體如下:

問題描述:

在2^k*2^k個方格組成的棋盤中,有一個方格被占用,用下圖的4種L型骨牌覆蓋所有棋盤上的其余所有方格,不能重疊。

Python3解決棋盤覆蓋問題的方法示例

代碼如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def chess(tr,tc,pr,pc,size):
  global mark
  global table
  mark+=1
  count=mark
  if size==1:
    return
  half=size//2
  if pr<tr+half and pc<tc+half:
    chess(tr,tc,pr,pc,half)
  else:
    table[tr+half-1][tc+half-1]=count
    chess(tr,tc,tr+half-1,tc+half-1,half)
  if pr<tr+half and pc>=tc+half:
    chess(tr,tc+half,pr,pc,half)
  else:
    table[tr+half-1][tc+half]=count
    chess(tr,tc+half,tr+half-1,tc+half,half)
  if pr>=tr+half and pc<tc+half:
    chess(tr+half,tc,pr,pc,half)
  else:
    table[tr+half][tc+half-1]=count
    chess(tr+half,tc,tr+half,tc+half-1,half)
  if pr>=tr+half and pc>=tc+half:
    chess(tr+half,tc+half,pr,pc,half)
  else:
    table[tr+half][tc+half]=count
    chess(tr+half,tc+half,tr+half,tc+half,half)
def show(table):
  n=len(table)
  for i in range(n):
    for j in range(n):
      print(table[i][j],end=' ')
    print('')
mark=0
n=8
table=[[-1 for x in range(n)] for y in range(n)]
chess(0,0,2,2,n)
show(table)

n是棋盤寬度,必須是2^k,本例中n=8,特殊格子在(2,2)位置,如下圖所示:

Python3解決棋盤覆蓋問題的方法示例

采用分治法每次把棋盤分成4份,如果特殊格子在這個小棋盤中則繼續分成4份,如果不在這個小棋盤中就把該小棋盤中靠近中央的那個格子置位,表示L型骨牌的1/3占據此處,每一次遞歸都會遍歷查詢4個小棋盤,三個不含有特殊格子的棋盤置位的3個格子正好在大棋盤中央構成一個完整的L型骨牌,依次類推,找到全部覆蓋方法。運行結果如下:

Python3解決棋盤覆蓋問題的方法示例

希望本文所述對大家Python程序設計有所幫助。

原文鏈接:http://blog.csdn.net/littlethunder/article/details/25288969

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 国产三级精品在线 | 黄色综合 | 欧美综合一区 | 亚洲精品中文字幕在线观看 | 久久精品在线 | 日韩精品一区二区三区 | 国产免费网址 | 国产毛片久久久 | 国产91在线观看 | 日本三级中国三级99人妇网站 | 国产一级片 | 久久h| 在线日韩视频 | 国产精品伦理一区二区 | 国产精一区| av男人的天堂在线 | 一本大道久久a久久精品综合1 | 日韩在线欧美 | 黑人精品 | 久久久久亚洲精品 | 亚洲精品国产电影 | 欧美久久精品 | 在线观看免费黄视频 | 免费看黄在线网站 | 欧美精品日韩精品 | 国产精品久久久久永久免费观看 | 在线欧美亚洲 | a视频网站 | 欧美视频成人 | 日韩国产一区二区三区 | 国产日韩一区二区 | 亚洲三区在线观看 | 亚洲国产精品一区二区三区 | 亚洲毛片在线 | 美女视频一区二区三区 | 亚洲福利精品 | 久草观看 | 国产在线视频xxx | 国产一区二区久久 | 在线视频国产一区 | 成人精品久久久 |