㈠ python能做什麼有趣的東西
python能做什麼有趣的東西?下面給大家介紹35個Python實例:
1. Python3 實現圖片識別
2. Python3 圖片隱寫術
3. 200 行 Python 代碼實現 2048
4. Python實現3D建模工具
5. 使用 Python 定製詞雲
相關推薦:《Python教程》
6. Python3 智能裁切圖片
7.微信變為聊天機器人
8. 使用 Python 解數學方程
9. 使用 Python 創建照片馬賽克
10. Python 基於共現提取《釜山行》人物關系
11. Python 氣象數據分析:《Python 數據分析實戰》
12. NBA常規賽結果預測:利用Python進行比賽數據分析
13. Python 的循環語句和隱含波動率的計算
14. K-近鄰演算法實現手寫數字識別系統
15. 數獨游戲的 Python 實現與破解
16. 基於 Flask 與 MySQL 實現番劇推薦系
17. Python 實現英文新聞摘要自動提取
18. Python 解決哲學家就餐問題
19. Ebay 在線拍賣數據分析
20. 神經網路實現人臉識別任務
21. 使用 Python 解數學方程
22. Python3 實現火車票查詢工具
23. Python 實現埠掃描器
24. Python3 實現可控制肉雞的反向Shell
25. Python 實現 FTP 弱口令掃描器
26. 基於PyQt5 實現地圖中定位相片拍攝位置
27. Python實現網站模擬登陸
28.Python實現簡易區域網視頻聊天工具
29. 基於 TCP 的 python 聊天程序
30. Python3基於Scapy實現DDos
31. 高德API + Python 解決租房問題
32. 基於 Flask 與 RethinkDB 實現TODO List
33. Python3 實現簡單的 Web 伺服器
34. Python 實現 Redis 非同步客戶端
35. 仿 StackOverflow 開發在線問答系統
㈡ 數獨演算法思路
數獨(數和)(英:Cross Sums;日:カックロ)是一種數學智力游戲。數和把填字游戲和數獨巧妙地結合在一起,採用填字游戲式的棋盤,解題時在空格中填上1-9的數字。這種游戲不僅需要邏輯思維能力,還需要一點加法運算。
電腦自動生成數獨游戲的謎題
要得出所有滿足條件的組合確實不是件容易的事情(主要是很多,列印起來很慢) 。但偶們的目標只是每次能得到一個新的組合,然後從格子裡面隨機遮掉一些數字就可以了。所以只需要在解數獨游戲演算法的基礎上稍作修改即可。
所以,演算法的步驟是:
1.往第一行或第一列隨機填1-9的數字
2.調用解數獨演算法得到一個結果
3.每行隨機遮掉1-8個數字。如果需要較大的難度,也可以將1-8改為2-8或3-8,等等。
以下是console工程的代碼:
// sudoku.cpp : 定義控制台應用程序的入口點。
// by superarhow([email protected])
#include "stdafx.h"
#include "conio.h"
#define SUCCESS 1
#define _FAILED 0
/* 地圖類型9*9的char,每個char從0-9,0表示待填 */
typedef char MAPTYPE[9][9];
/* 行數據,同時用作「可能性」數據。如LINETYPE a; 當a[0]為真時表示
當前位置可填1,a[1]為真時表示可填2,以此類推 */
typedef char LINETYPE[9];
typedef void (*ONMAPOKCALLBACK)(MAPTYPE map);
/* 列印地圖 */
void mp_map(MAPTYPE dest)
{
for ( int j = 0; j < 9; j++ )
{
for ( int i = 0; i < 9; i++ )
{
printf("%d ", dest[i][j]);
}
printf("\n");
}
printf("\n");
}
int fill_line(MAPTYPE dest, int line, ONMAPOKCALLBACK callback);
/* 填下一個格子。本行的可能性已在調用前算好,要考慮的是列的可能性和九宮格的可能性 */
/* nums_possible : array (0-8) means possible of number (1-9) */
int fill_pos(MAPTYPE dest, LINETYPE nums_possible, int line, int pos, ONMAPOKCALLBACK callback)
{
if ( pos >= 9 )
{
return fill_line(dest, line + 1, callback);
}
if ( dest[pos][line] != 0 ) return fill_pos(dest, nums_possible, line, pos + 1, callback);
for ( int i = 0; i < 9; i++ )
{
if ( !nums_possible[i] ) continue;
/* 檢查本列是否重復 */
int vetical_failed = 0;
for ( int j = 0; j < 9; j++ )
if ( dest[pos][j] == i + 1 )
{
vetical_failed = 1;
break;
}
if ( vetical_failed ) continue;
/* 檢查九宮格是否重復 */
int nine_failed = 0;
int m = pos / 3;
int n = line / 3;
m *= 3;
n *= 3;
for ( int y = n; y < n + 3; y++ )
{
for ( int x = m; x < m + 3; x++ )
{
if ( dest[x][y] == i + 1 )
{
nine_failed = 1;
break;
}
}
if ( nine_failed ) break;
}
if ( nine_failed ) continue;
/* all ok, try next position */
dest[pos][line] = i + 1;
nums_possible[i] = 0;
if ( fill_pos(dest, nums_possible, line, pos + 1, callback) )
{
/* 本行已全部OK,嘗試下一行 */
if ( fill_line(dest, line + 1, callback) ) return SUCCESS;
/* 下一行失敗,重新嘗試本位置的剩餘可能性 */
}
nums_possible[i] = 1;
dest[pos][line] = 0;
}
return _FAILED;
}
/* 填下一行 */
int fill_line(MAPTYPE dest, int line, ONMAPOKCALLBACK callback)
{
if ( line >= 9 )
{
/* map */
callback(dest);
return SUCCESS;
}
LINETYPE nums;
LINETYPE saveline;
/* calc possibility(for the current line) */
for ( int i = 0; i < 9; i++ ) nums[i] = 1; /* all can be */
for ( int i = 0; i < 9; i++ )
{
char n = dest[i][line];
/* save line */
saveline[i] = dest[i][line];
if ( n != 0 ) nums[n - 1] = 0; /* appears */
}
if ( !fill_pos(dest, nums, line, 0, callback) )
{
/* restore line */
for ( int i = 0; i < 9; i++ ) dest[i][line] = saveline[i];
return _FAILED;
}
return SUCCESS;
}
MAPTYPE g_result;
void on_map_ok(MAPTYPE map)
{
memcpy(g_result, map, sizeof(MAPTYPE));
}
#include "windows.h"
int _tmain(int argc, _TCHAR* argv[])
{
MAPTYPE dest;
memset(dest, 0, sizeof(MAPTYPE));
srand( GetTickCount() );
/* 隨機填充第一行 */
char ch[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for ( int i = 0; i < 9; i++ )
{
int p = rand() % 9;
char t = ch[p];
ch[p] = ch[i];
ch[i] = t;
}
for ( int i = 0; i < 9; i++ ) dest[i][0] = ch[i];
if ( fill_line(dest, 0, on_map_ok) )
{
/* 修剪掉一些塊 */
for ( int i = 0; i < 9; i++ )
{
/* 調整n的取值范圍可改變難度 %6 + 3是比較難的 */
int n = (rand() % 6) + 3;
for ( int j = 0; j < 9; j++ ) ch[j] = j; /* ch: index to erase */
for ( int j = 0; j < 9; j++ )
{
int p = rand() % 9;
char t = ch[p];
ch[p] = ch[i];
ch[i] = t;
}
for ( int j = 0; j < n; j++ ) g_result[ch[j]][i] = 0;
}
mp_map(g_result);
}
getch();
return 0;
}
看完這些,你對數獨的演算法了解了嗎?
㈢ python可以做哪些有趣的事情
1. Python3 實現色情圖片識別
2. Python3 圖片隱寫術
3. 200 行 Python 代碼實現 2048
4. Python實現3D建模工具
5. 使用 Python 定製詞雲
6. Python3 智能裁切圖片
7.微信變為聊天機器人
8. 使用 Python 解數學方程
9. 使用 Python 創建照片馬賽克
10. Python 基於共現提取《釜山行》人物關系
11. Python 氣象數據分析:《Python 數據分析實戰》
12. NBA常規賽結果預測:利用Python進行比賽數據分析
13. Python 的循環語句和隱含波動率的計算
14. K-近鄰演算法實現手寫數字識別系統
15. 數獨游戲的 Python 實現與破解
16. 基於 Flask 與 MySQL 實現番劇推薦系
17. Python 實現英文新聞摘要自動提取
18. Python 解決哲學家就餐問題
19. Ebay 在線拍賣數據分析
20. 神經網路實現人臉識別任務
21. 使用 Python 解數學方程
22. Python3 實現火車票查詢工具
23. Python 實現埠掃描器
24. Python3 實現可控制肉雞的反向Shell
25. Python 實現 FTP 弱口令掃描器
26. 基於PyQt5 實現地圖中定位相片拍攝位置
27. Python實現網站模擬登陸
28.Python實現簡易區域網視頻聊天工具
29. 基於 TCP 的 python 聊天程序
30. Python3基於Scapy實現DDos
31. 高德API + Python 解決租房問題
32. 基於 Flask 與 RethinkDB 實現TODO List