中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

php裝修公司網(wǎng)站源碼哪個(gè)搜索引擎能搜敏感內(nèi)容

php裝修公司網(wǎng)站源碼,哪個(gè)搜索引擎能搜敏感內(nèi)容,亞洲永久免費(fèi)云服務(wù)器,用struts2框架做的網(wǎng)站解數(shù)獨(dú) https://leetcode.cn/problems/sudoku-solver/description/ 描述 編寫(xiě)一個(gè)程序,通過(guò)填充空格來(lái)解決數(shù)獨(dú)問(wèn)題數(shù)獨(dú)的解法需 遵循如下規(guī)則: 數(shù)字 1-9 在每一行只能出現(xiàn)一次數(shù)字 1-9 在每一列只能出現(xiàn)一次數(shù)字 1-9 在每一個(gè)以粗實(shí)線分隔的 3x3 宮內(nèi)…

解數(shù)獨(dú)

  • https://leetcode.cn/problems/sudoku-solver/description/

描述

  • 編寫(xiě)一個(gè)程序,通過(guò)填充空格來(lái)解決數(shù)獨(dú)問(wèn)題
  • 數(shù)獨(dú)的解法需 遵循如下規(guī)則:
    • 數(shù)字 1-9 在每一行只能出現(xiàn)一次
    • 數(shù)字 1-9 在每一列只能出現(xiàn)一次
    • 數(shù)字 1-9 在每一個(gè)以粗實(shí)線分隔的 3x3 宮內(nèi)只能出現(xiàn)一次。(請(qǐng)參考示例圖)
  • 數(shù)獨(dú)部分空格內(nèi)已填入了數(shù)字,空白格用 ‘.’ 表示

示例 1

輸入:board = [["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]]
輸出:[["5","3","4","6","7","8","9","1","2"],["6","7","2","1","9","5","3","4","8"],["1","9","8","3","4","2","5","6","7"],["8","5","9","7","6","1","4","2","3"],["4","2","6","8","5","3","7","9","1"],["7","1","3","9","2","4","8","5","6"],["9","6","1","5","3","7","2","8","4"],["2","8","7","4","1","9","6","3","5"],["3","4","5","2","8","6","1","7","9"]]

解釋:輸入的數(shù)獨(dú)如上圖所示,唯一有效的解決方案如下所示:

提示

  • board.length == 9
  • board[i].length == 9
  • board[i][j] 是一位數(shù)字或者 ‘.’
  • 題目數(shù)據(jù) 保證 輸入數(shù)獨(dú)僅有一個(gè)解

Typescript 版算法實(shí)現(xiàn)


1 ) 方案1: 回溯

/**Do not return anything, modify board in-place instead.*/
function solveSudoku(board: string[][]): void {const line: boolean[][] = Array.from({ length: 9 }, () => Array(9).fill(false));const column: boolean[][] = Array.from({ length: 9 }, () => Array(9).fill(false));const block: boolean[][][] = Array.from({ length: 3 }, () => Array.from({ length: 3 }, () => Array(9).fill(false)));const spaces: number[][] = [];// 初始化狀態(tài)for (let i = 0; i < 9; i++) {for (let j = 0; j < 9; j++) {if (board[i][j] === '.') {spaces.push([i, j]);} else {const digit = parseInt(board[i][j]) - 1;line[i][digit] = true;column[j][digit] = true;block[Math.floor(i / 3)][Math.floor(j / 3)][digit] = true;}}}// 深度優(yōu)先搜索函數(shù)function dfs(pos: number): boolean {if (pos === spaces.length) {return true;}const [i, j] = spaces[pos];for (let digit = 0; digit < 9; digit++) {if (!line[i][digit] && !column[j][digit] && !block[Math.floor(i / 3)][Math.floor(j / 3)][digit]) {line[i][digit] = true;column[j][digit] = true;block[Math.floor(i / 3)][Math.floor(j / 3)][digit] = true;board[i][j] = (digit + 1).toString();if (dfs(pos + 1)) {return true;}// 回溯line[i][digit] = false;column[j][digit] = false;block[Math.floor(i / 3)][Math.floor(j / 3)][digit] = false;board[i][j] = '.';}}return false;}dfs(0);
}

2 ) 方案2: 位運(yùn)算優(yōu)化

/**Do not return anything, modify board in-place instead.*/
function solveSudoku(board: string[][]): void {const line: number[] = Array(9).fill(0);const column: number[] = Array(9).fill(0);const block: number[][] = Array.from({ length: 3 }, () => Array(3).fill(0));const spaces: number[][] = [];// 翻轉(zhuǎn)函數(shù),用于設(shè)置或清除位function flip(i: number, j: number, digit: number) {const mask = 1 << digit;line[i] ^= mask;column[j] ^= mask;block[Math.floor(i / 3)][Math.floor(j / 3)] ^= mask;}// 初始化狀態(tài)for (let i = 0; i < 9; i++) {for (let j = 0; j < 9; j++) {if (board[i][j] === '.') {spaces.push([i, j]);} else {const digit = parseInt(board[i][j]) - 1;flip(i, j, digit);}}}// 深度優(yōu)先搜索函數(shù)function dfs(pos: number): boolean {if (pos === spaces.length) {return true;}const [i, j] = spaces[pos];let mask = 0x1ff & ~(line[i] | column[j] | block[Math.floor(i / 3)][Math.floor(j / 3)]);while (mask > 0) {const digit = Math.log2(mask & -mask); // 找到最右側(cè)的 1 的位置flip(i, j, digit);board[i][j] = (digit + 1).toString();if (dfs(pos + 1)) {return true;}flip(i, j, digit);mask &= mask - 1; // 將最右側(cè)的 1 置為 0}return false;}dfs(0);
}

3 ) 方案3: 枚舉優(yōu)化

/**Do not return anything, modify board in-place instead.*/
function solveSudoku(board: string[][]): void {const line: number[] = Array(9).fill(0);const column: number[] = Array(9).fill(0);const block: number[][] = Array.from({ length: 3 }, () => Array(3).fill(0));const spaces: number[][] = [];// 翻轉(zhuǎn)函數(shù),用于設(shè)置或清除位function flip(i: number, j: number, digit: number) {const mask = 1 << digit;line[i] ^= mask;column[j] ^= mask;block[Math.floor(i / 3)][Math.floor(j / 3)] ^= mask;}// 初始化已知數(shù)字的狀態(tài)for (let i = 0; i < 9; i++) {for (let j = 0; j < 9; j++) {if (board[i][j] !== '.') {const digit = parseInt(board[i][j]) - 1;flip(i, j, digit);}}}// 嘗試通過(guò)唯一解填充空格let modified: boolean;do {modified = false;for (let i = 0; i < 9; i++) {for (let j = 0; j < 9; j++) {if (board[i][j] !== '.') {continue;}let mask = 0x1ff & ~(line[i] | column[j] | block[Math.floor(i / 3)][Math.floor(j / 3)]);if ((mask & (mask - 1)) === 0 && mask !== 0) { // mask 的二進(jìn)制表示僅有一個(gè) 1const digit = Math.log2(mask); // 找到最右側(cè)的 1 的位置flip(i, j, digit);board[i][j] = (digit + 1).toString();modified = true;}}}} while (modified);// 記錄剩余未填充的空格for (let i = 0; i < 9; i++) {for (let j = 0; j < 9; j++) {if (board[i][j] === '.') {spaces.push([i, j]);}}}// 深度優(yōu)先搜索函數(shù)function dfs(pos: number): boolean {if (pos === spaces.length) {return true;}const [i, j] = spaces[pos];let mask = 0x1ff & ~(line[i] | column[j] | block[Math.floor(i / 3)][Math.floor(j / 3)]);while (mask > 0) {const digit = Math.log2(mask & -mask); // 找到最右側(cè)的 1 的位置flip(i, j, digit);board[i][j] = (digit + 1).toString();if (dfs(pos + 1)) {return true;}flip(i, j, digit);mask &= mask - 1; // 將最右側(cè)的 1 置為 0}return false;}dfs(0);
}
http://www.risenshineclean.com/news/11490.html

相關(guān)文章:

  • 校園二手交易網(wǎng)站開(kāi)發(fā)背景百度推廣有用嗎
  • 網(wǎng)站項(xiàng)目開(kāi)發(fā)案seo技術(shù)快速網(wǎng)站排名
  • 支付寶 收費(fèi) 網(wǎng)站開(kāi)發(fā)東莞seo
  • 做網(wǎng)站推廣的好處seo外包靠譜
  • 好品質(zhì)高端網(wǎng)站設(shè)計(jì)廣州百度快速優(yōu)化排名
  • 化妝品網(wǎng)站欄目設(shè)計(jì)推廣策劃方案怎么寫(xiě)
  • 做網(wǎng)站人網(wǎng)頁(yè)設(shè)計(jì)制作網(wǎng)站素材
  • 注冊(cè)登錄汕頭搜索引擎優(yōu)化服務(wù)
  • 找人做彩票網(wǎng)站多少錢(qián)seo推廣論壇
  • 騰網(wǎng)站建設(shè)谷歌google下載安卓版 app
  • 中國(guó)網(wǎng)站的特點(diǎn)seo數(shù)據(jù)統(tǒng)計(jì)分析工具有哪些
  • 免費(fèi)軟件下載網(wǎng)站app南京百度網(wǎng)站推廣
  • 做網(wǎng)站時(shí)分類(lèi)標(biāo)題和分類(lèi)描述搜索詞和關(guān)鍵詞
  • 鮮花加盟網(wǎng)站建設(shè)網(wǎng)站優(yōu)化與seo
  • 商城網(wǎng)站建設(shè)浩森宇特好看的網(wǎng)站ui
  • 成都網(wǎng)站建設(shè)公司電話seo網(wǎng)絡(luò)推廣公司
  • 香港網(wǎng)站不備案淘寶站外引流推廣方法
  • 建設(shè)網(wǎng)站6980塊錢(qián)貴嗎山西seo
  • 聊城網(wǎng)站建設(shè)方案網(wǎng)站推廣的基本方法有
  • 常州模板建站哪家好四年級(jí)寫(xiě)一小段新聞
  • 浪琴手表網(wǎng)站建設(shè)圖公眾號(hào)引流推廣平臺(tái)
  • 禁止拿我們的網(wǎng)站做宣傳市場(chǎng)調(diào)研報(bào)告3000字范文
  • 國(guó)外 網(wǎng)站頁(yè)面跨境電商關(guān)鍵詞工具
  • 免費(fèi)圖片素材網(wǎng)南京怎樣優(yōu)化關(guān)鍵詞排名
  • 東營(yíng)建設(shè)信息網(wǎng)站百度手機(jī)導(dǎo)航官方新版
  • 門(mén)戶網(wǎng)站案例發(fā)稿推廣
  • 單位網(wǎng)站平臺(tái)建設(shè)匯報(bào)sem搜索
  • 創(chuàng)建學(xué)校網(wǎng)站今天的重要新聞
  • 竹子建站下載哈爾濱最新消息
  • 怎么做自己的推廣網(wǎng)站google seo 優(yōu)化