準備フェーズ
1、GitHubのアドレス
2、PSP形態
psp2.1 | 推定時間がかかる(分) | 実際の時間がかかる(分) |
---|---|---|
計画 | 30 | 30 |
このタスクが必要とどのくらいの時間を見積もります | 20 | 15 |
開発 | 150 | 120 |
(新しい技術を学ぶ含む)ニーズ分析 | 240 | 300 |
設計ドキュメントの生成 | 20 | 30 |
デザインレビュー | 10 | 10 |
コードの仕様(現在の開発のための適切な規範の開発) | 120 | 120 |
具体的な設計 | 30 | 30 |
具体的なコーディング | 240 | 180 |
コードレビュー | 20 | 15 |
検査(セルフテスト、コードを変更し、変更を提出) | 120 | 240 |
レポート | 30 | 60 |
テストレポート | 30 | 50 |
量を計算します | 20 | 30 |
その後まとめ、およびプロセス改善計画 | 60 | 60 |
トータル | 1140 | 1290 |
初め
1、思考
Baiduの百科事典の説明:
数独は、ディスクで9つの宮殿、各宮殿が9個の小細胞に分かれています。デジタル知られており、論理および推論を使用して、この八十から一グリッドを解決する特定の条件を考えると、他の空間に番号1-9を入力します。1-9ので、各番号は、としても知られている各行、各列および各宮殿、一度だけ表示されていることを「正方形」。
決して連絡しない郭シュウは私を分離するために、私がいなくても、最も基本的な数独のルールが不明確である可能性があるため、これは、非常に、非常に、非常に困難なトピックです。それが唯一の3つの論理判断だが、数独の正方形を解決しても、まだいくつかの時間を必要としています。
2、思考
ブール結果の正当性の配列への3直接アクセスして、すべての判断のまず。
if(row[x][i] == false && col[y][i] == false && little_shudu[area][i] == false)
それでは、我々は結果グリッドを得ることができる場合に充填することができます。
ボックスの正当性を取得した後、我々はバックトラック、DFSによって横断しました
shudu[x][y] = i;
row[x][i] = true;
col[y][i] = true;
if(gx != 1 || gy != 1)
little_shudu[area][i] = true;
dfs(index + 1,maxscan,jie,gx,gy);
shudu[x][y] = 0;
row[x][i] = false;
col[y][i] = false;
if(gx != 1 || gy != 1)
little_shudu[area][i] = false;
図3に示すように、モジュール
1、入力モジュール
要件がINPUT.TXTから入力されているので、次のように、入力モジュールは、次のとおり
void input(int x,int gx,int gy)
{
memset(row,false,sizeof(row));
memset(col,false,sizeof(col));
memset(little_shudu,false,sizeof(little_shudu));
for(int i = 0 ; i < x ; i++){
for(int j = 0 ; j < x ; j++){
fscanf(fp, "%d", &shudu[i][j]);
int temp_i = i / gx;
int temp_j = j / gy;
int area = temp_i * gx + temp_j;
if(shudu[i][j] != 0){
int temp = shudu[i][j];
row[i][temp] = true;
col[j][temp] = true;
if(gx != 1 || gy != 1 ){
little_shudu[area][temp] = true;
}
}
}
}
}
図2に示すように、出力モジュール
ファイルの数を入力することによってのみ得て解決した後、ファイルoutput.txtとを出力
void print(int x)
{
for(int i = 0 ; i < x ; i++)
{
for(int j = 0 ; j < x ; j++)
{
if(j == x - 1) {
fprintf(fp, "%d\n", shudu[i][j]);
}
else {
fprintf(fp, "%d ", shudu[i][j]);
}
}
}
fprintf(fp, "\n");
}
図3に示すように、溶液モジュール
つまり、最初に満たされた計算の合法性を確認してください。
void dfs(int index , int maxscan,int jie,int gx , int gy)
{
if(index >= maxscan)
{
print(jie);
return ;
}
int x = index / jie ;
int y = index % jie ;
int temp_i = x / gx;
int temp_j = y / gy;
int area = temp_i * gx + temp_j;
if(shudu[x][y] == 0)
{
for(int i = 1 ; i <= jie ; i++)
{
if(row[x][i] == false && col[y][i] == false && little_shudu[area][i] == false)
{
shudu[x][y] = i;
row[x][i] = true;
col[y][i] = true;
if(gx != 1 || gy != 1)
little_shudu[area][i] = true;
dfs(index + 1,maxscan,jie,gx,gy);
shudu[x][y] = 0;
row[x][i] = false;
col[y][i] = false;
if(gx != 1 || gy != 1)
little_shudu[area][i] = false;
}
}
}
else{
dfs(index + 1,maxscan,jie,gx,gy);
}
}
4、パフォーマンステスト
私は大丈夫、李カク不明のように感じます。
5、テストを実行します
三つのグリッドがやりました!
四のグリッドはやりました!
(中間体568を省略しています)
七のグリッドがやりました!
もちろん、二乗なしで完全になります!
合計コード:
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include<string>
#include <cstring>
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <fstream>
using namespace std;
const int maxn = 1000;
const int sizen = 16;
int shudu[sizen][sizen];//存储数独
bool row[sizen][sizen];//row[i][j]判断i行j是否被填过
bool col[sizen][sizen];//col[i][j]判断i列j是否被填过
bool little_shudu[sizen][sizen];//little_sudu[i][j]判断从左往右开始的第i个小数独中,j是否被填过;
FILE* fp;
void input(int x, int gx, int gy) {
memset(row, false, sizeof(row));
memset(col, false, sizeof(col));
memset(little_shudu, false, sizeof(little_shudu));
for (int i = 0; i < x; i++) {
for (int j = 0; j < x; j++) {
scanf("%d", &shudu[i][j]);
int temp_i = i / gx;
int temp_j = j / gy;
int area = temp_i * gx + temp_j;
if (shudu[i][j] != 0) {
int temp = shudu[i][j];
row[i][temp] = true;
col[j][temp] = true;
if (gx != 1 || gy != 1) {
little_shudu[area][temp] = true;
}
}
}
}
}
void print(int x) {
for (int i = 0; i < x; i++) {
for (int j = 0; j < x; j++) {
if (j == x - 1) {
printf("%d\n", shudu[i][j]);
}
else {
printf("%d ", shudu[i][j]);
}
}
}
printf("\n");
}
void dfs(int index, int maxscan, int jie, int gx, int gy) {
if (index >= maxscan) {
print(jie);
return;
}
int x = index / jie;
int y = index % jie;
int temp_i = x / gx;
int temp_j = y / gy;
int area = temp_i * gx + temp_j;
if (shudu[x][y] == 0) {
for (int i = 1; i <= jie; i++) {
if (row[x][i] == false && col[y][i] == false && little_shudu[area][i] == false) {
shudu[x][y] = i;
row[x][i] = true;
col[y][i] = true;
if (gx != 1 || gy != 1)
little_shudu[area][i] = true;
dfs(index + 1, maxscan, jie, gx, gy);
shudu[x][y] = 0;
row[x][i] = false;
col[y][i] = false;
if (gx != 1 || gy != 1)
little_shudu[area][i] = false;
}
}
}
else {
dfs(index + 1, maxscan, jie, gx, gy);
}
}
int main(int argc, char *argv[]) {
int pan, size, jie, gx, gy;
int in, out;
for (int i = 0; i < argc; i++)
{
if (strlen(argv[i]) == 1)
{
if (i == 2)
size = atoi(argv[i]);
if (i == 4)
pan = atoi(argv[i]);
}
else if (argv[i][0] == '-' && argv[i][1] == 'i') {
i++;
in = i;
}
else if (argv[i][0] == '-' && argv[i][1] == 'o') {
i++;
out = i;
}
}
freopen(argv[in], "r", stdin);
freopen(argv[out], "w", stdout);
jie = size;
if (size == 4) {
gx = gy = 2;
}
else if (size == 6) {
gx = 2;
gy = 3;
}
else if (size == 8) {
gx = 4;
gy = 2;
}
else if (size == 9) {
gx = gy = 3;
}
else gx = gy = 1;
for (int i = 0; i < pan; i++) {
input(size, gx, gy);
dfs(0, jie*jie, jie, gx, gy);
}
return 0;
}