POJ3074----Sudoku

Python环境搭建与PyCharm安装教程:从解释器配置到第三方库管理全指南 编程学习的起点往往不是语法本身,而是开发环境的构建。Python作为一门解释型高级语言,其运行依赖解释器与依赖包管理,而集成开发环境(IDE)则能显著提升编码效率。理解解释器、虚拟环境、包管理工具(如pip)的工作原理,是进行数据分析、爬虫脚本或Web开发的基础前提。良好的工具链配置不仅能规避多版本冲突、路径异常等常见工程问题,还能为后续自动化运维和人工智能项目奠定稳定基石。从官方渠道获取Python解释器,再到选用合适的PyCharm版本,最后在虚拟环境中安装pandas等第三方库,这是一条完整且安全的工 阅读详情
Sudoku
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 8575 Accepted: 3074

Description

In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgrids. For example,

.2738..1.
.1...6735
.......29
3.5692.8.
.........
.6.1745.3
64.......
9518...7.
.8..6534.

Given some of the numbers in the grid, your goal is to determine the remaining numbers such that the numbers 1 through 9 appear exactly once in (1) each of nine 3 × 3 subgrids, (2) each of the nine rows, and (3) each of the nine columns.

Input

The input test file will contain multiple cases. Each test case consists of a single line containing 81 characters, which represent the 81 squares of the Sudoku grid, given one row at a time. Each character is either a digit (from 1 to 9) or a period (used to indicate an unfilled square). You may assume that each puzzle in the input will have exactly one solution. The end-of-file is denoted by a single line containing the word “end”.

Output

For each test case, print a line representing the completed Sudoku puzzle.

Sample Input

.2738..1..1...6735.......293.5692.8...........6.1745.364.......9518...7..8..6534.
......52..8.4......3...9...5.1...6..2..7........3.....6...1..........7.4.......3.
end

Sample Output

527389416819426735436751829375692184194538267268174593643217958951843672782965341
416837529982465371735129468571298643293746185864351297647913852359682714128574936

Source

Stanford Local 2006

把数独问题转成精确覆盖,课设要做这个就来学了下dlx

/*************************************************************************
    > File Name: sudoku.cpp
    > Author: ALex
    > Mail: 405045132@qq.com 
    > Created Time: 2015年01月06日 星期二 14时46分52秒
 ************************************************************************/

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int n = 350;
const int m = 800;
const int inf = 0x3f3f3f3f;
const int N = 1000 * 1000;
bool mat[1000][1000];
char su[100];
int cnt[m];
int most;
bool ans[N];
int head;

struct Node
{
	int up, down, left, right;
	int col, row;
}node[N];

void init (int m)
{
	memset (ans, 0, sizeof(ans));
	for (int i = 0; i <= m; ++i)
	{
		node[i].left = i - 1;
		node[i].right = i + 1;
		node[i].col = i;
		node[i].up = i;
		node[i].down = i;
		cnt[i] = 0;
	}
	node[0].left = m;
	node[m].right = 0;
}

void remove(int c)
{
	node[node[c].left].right = node[c].right;
	node[node[c].right].left = node[c].left;
	for (int i = node[c].down; i != c; i = node[i].down)
	{
		for (int j = node[i].right; j != i; j = node[j].right)
		{
			--cnt[node[j].col];
			node[node[j].up].down = node[j].down;
			node[node[j].down].up = node[j].up;
		}
	}
}

void resume(int c)
{
	node[node[c].left].right = c;
	node[node[c].right].left = c;
	for (int i = node[c].up; i != c; i = node[i].up)
	{
		for (int j = node[i].left; j != i; j = node[j].left)
		{
			++cnt[node[j].col];
			node[node[j].down].up = j;
			node[node[j].up].down = j;
		}
	}
}

bool Dacing_Link_X()
{
	if (node[324].right == 324)
	{
		return true;
	}
	int mins = inf;
	int c;
	for (int i = node[324].right; i != 324; i = node[i].right)
	{
		if (cnt[i] < mins)
		{
			mins = cnt[i];
			c = i;
		}
	}
	remove(c);
	for (int i = node[c].down; i != c; i = node[i].down)
	{
		for (int j = node[i].right; j != i; j = node[j].right)
		{
			remove(node[j].col);
		}
		ans[node[i].row] = 1;
		if (Dacing_Link_X())
		{
			return true;
		}
		for (int j = node[i].left; j != i; j = node[j].left)
		{
			resume(node[j].col);
		}
		ans[node[i].row] = 0;
	}
	resume(c);
	return false;
}

int in_grid(int i, int j)
{
	++i;
	++j;
	if (1 <= i && i <= 3 && 1 <= j && j <= 3)
	{
		return 1;
	}
	if (1 <= i && i <= 3 && 4 <= j && j <= 6)
	{
		return 2;
	}
	if (1 <= i && i <= 3 && 7 <= j && j <= 9)
	{
		return 3;
	}
	if (4 <= i && i <= 6 && 1 <= j && j <= 3)
	{
		return 4;
	}
	if (4 <= i && i <= 6 && 4 <=j && j <= 6)
	{
		return 5;
	}
	if (4 <= i && i <= 6 && 7 <= j && j <= 9)
	{
		return 6;
	}
	if (7 <= i && i <= 9 && 1 <= j && j <= 3)
	{
		return 7;
	}
	if (7 <= i && i <= 9 && 4 <= j && j <= 6)
	{
		return 8;
	}
	if (7 <= i && i <= 9 && 7 <= j && j <= 9)
	{
		return 9;
	}
}

void add(int i, int j, int k)
{
	int x = (i * 9 + j) * 9 + k;
	mat[x][i * 9 + j] = 1;
	mat[x][81 + i * 9 + k] = 1;
	mat[x][162 + j * 9 + k] = 1;
	int g = in_grid(i, j);
	mat[x][243 + (g - 1) * 9 + k] = 1;
}

int main()
{
//	printf("please enter your sudoku\n");
//
	while (~scanf("%s", su))
	{
		if (!strcmp(su, "end"))
		{
			break;
		}
		most = 1000;
		memset (mat, 0, sizeof(mat));
		init(324);
		int cur = 325;
		for (int i = 0; i < 9; ++i)
		{
			for (int j = 0; j < 9; ++j)
			{
				if (su[i * 9 + j] == '.')
				{
					for (int k = 0; k < 9; ++k)
					{
						add(i, j, k);
					}
				}
				else
				{
					int k = su[i * 9 + j] - '1';
					add(i, j, k);
				}
			}
		}
		for (int i = 0; i < 729; ++i)
		{
			int s = cur;
			int pre = cur;
			for (int j = 0; j < 324; ++j)
			{
				if (!mat[i][j])
				{
					continue;
				}
				int pos = j;
				node[cur].up = node[pos].up;
				node[node[pos].up].down = cur;
				node[cur].down = pos;
				node[pos].up = cur;
				node[cur].row = i;
				node[cur].col = pos;
				node[cur].left = pre;
				node[pre].right = cur;
				node[cur].right = s;
				cnt[pos]++;
				node[s].left = cur;
				pre = cur;
				cur++;
			}
		}
		Dacing_Link_X();
		for (int i = 0; i < 81; ++i)
		{
			for (int j = 0; j < 9; ++j)
			{
				if (ans[i * 9 + j])
				{
					printf("%d", j + 1);
					break;
				}
			}
		}
		printf("\n");
	}
	return 0;
}


Obsidian笔记同步实战:基于Git的私有化部署与自动化管理 本文详细介绍了如何利用Git为Obsidian笔记构建私有化、自动化且免费的同步方案。通过安装配置Git与Obsidian-git插件,结合Gitee等远程仓库,实现笔记的版本管理、多设备同步与自动备份,打造安全可靠的知识管理体系。 阅读详情

相关推荐

使用3dmax Morpher制作Unity表情动画

关于游戏人物的面部表情动画 方案一:如果面部骨骼数丰富的话,可以直接做骨骼动画 方案二:采用变形器(3dmax是Morpher,maya是blendshape)修改相应通道的权重值来做表情动画 本文简述方案二的做法。 说明:本文截图中3dsMax版本为2017。笔者第一次使用3dsMax,欢迎指正。 3dmax中导入人物模型,选择需要变形的对象,即head。当前对象附带skin信息。 ...

写作帮助思考 2万+

poj 3074 Sudoku

Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7613   Accepted: 2696 Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3

u012647218的专栏 1029

从PCB走线到天线:用史密斯圆图搞定2.4GHz频段的阻抗匹配陷阱

本文深入探讨了2.4GHz频段PCB设计中阻抗匹配的挑战与解决方案,重点介绍了史密斯圆图在射频和天线阻抗匹配中的应用。通过实战案例和详细步骤,帮助工程师有效解决高频信号传输中的阻抗失配问题,提升物联网设备的通信性能。

uuu88的博客 728

POJ - 3074 Sudoku (数独--Dancing Links)

题意: 基本数独 分析: 将数独转化为精确覆盖 #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;cmath&gt; using namespace std; const int N=9; //n*n数独 const int maxn=N*N*N+10; const int maxm...

兜率工的博客 322

2024广东省职业技能大赛云计算——集群部署GitLab

题目是这样的:在Kubernetes集群中新建命名空间gitlab-ci,将GitLab部署到该命名空间下,Deployment和Service名称均为gitlab,以NodePort方式将80端口对外暴露为30880,设置GitLab服务root用户的密码为admin@123,将项目包demo-2048.tar.gz导入到GitLab中并命名为demo-2048。GitLab是一个功能强大且灵活的 DevOps 平台,为开发团队和企业提供了从代码管理到持续集成、交付和部署的一整套解决方案。

kuuuugua的博客 4404

Unity 多渠道分包工程化实践(大白话版):从“手工打包”到“一键出 30 个包还不翻车”

Unity多渠道分包工程化实践摘要(150字) 本文系统探讨Unity多渠道包自动化构建方案,提出基于BuildPipeline的工程化体系。核心包括:1)通过ScriptableObject/JSON管理渠道参数(包名、签名、SDK配置等);2)结合命令行与环境变量实现CI集成;3)开发通用Builder脚本支持资源动态替换与参数注入。重点分享了Android渠道包的签名配置、图标自动替换、宏定义注入等关键技术实现,并给出Jenkins流水线集成案例。该方案可支持日均数百个渠道包的自动化构建,显著提升分发

本博客聚焦游戏开发技巧、创业实战心得及大学热门课程干货。这里既有技术深度,也有思维广度,无论你是开发者、创业者还是高校学子,都能在这里找到适合自己的成长之路! 284

【POJ 3074】Sudoku【剪枝】

题意: 一个数独问题,类似的还有POJ2676 = POJ 2918 < POJ3074 < POJ3076,按难度排序。 解法: 大部分的题解都是用舞蹈链写的,但是实在不想学这个不太常用的算法,就一直尝试剪枝。成功剪了n小时...... 两个剪枝操作: 1.每次寻找可以填的数字最少的那个格子 2.每次更新的时候,顺便寻找...

lucius-liu.cn 639

时间门控拉曼进展

拉曼光谱就像是用光给分子拍“指纹照”,通过激光照射样品,散射光会揭示样品的分子结构。但问题来了,样品有时会发荧光,就像拍照时闪光灯太亮,把指纹照模糊了。时间门控拉曼光谱技术就像加了个“快门”,只在拉曼信号出现的那一瞬间开门,把慢吞吞的荧光挡在门外,这样就能拍到清晰的“指纹”。

qq_53529450的博客 540

POJ3074 Sudoku(数独(二))(位运算优化及DFS)

题目链接 (AC代码在最后面) Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgrids. For example, . 2 7 3 8 . . 1 . . 1 . . ...

悲伤无声地涌出来 1257

微信文件自动归档!手把手教你用OpenClaw搭个自己的“数字员工”,告别重复劳动

很多人说“AI是未来”,但未来不是靠喊口号的。OpenClaw的真正价值,是让你把重复劳动交出去,把时间留给真正需要创造力的事。这事真能干,而且不难。下载OpenClaw(GitHub仓库按我写的步骤跑一遍遇到坑,评论区留言——我亲自帮你看作者后记:上周五,我让AI自动归档了文件后,终于在5点准时下班。回家路上,我给它发了条消息:“干得漂亮”。它没回,但我知道——它在默默等我的下一条指令。

2601_94871597的博客 422

LabVIEW实现TCP通信

在本节中,我们将简要探讨TCP通信的基础知识,并以工业物联网平台TLINK中的云端设备数据发布设计为例,详细阐述在互联网环境下TCP客户端应用程序设计的基本方法。

不脱发的程序猿 1974

POJ3074 Sudoku

POJ3074 Sudoku 与POJ2676相比,这一题搜索时每一步都找到最好确定的点进行枚举 对于每行、每列、每个九宫格,都分别用一个9位二进制数保存还有那些数还可以填 对于每个位置,将其所在行、列、九宫格所对应的二进制数进行或运算即可得到该位置能填哪些数,用lowbit运算(取出最低的为1的数位)即可吧能填的数字取出。 其他见代码 1 #include <...

weixin_33953249的博客 103

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

POJ3074 Sudoku DFS

题目链接 http://poj.org/problem?id=3074 分析 用二进制数来表示可选填的数,每次扫描找可选数最小的填。 AC代码 #include <cstdio> const int maxn = 15; int r[maxn], c[maxn], p[maxn], cnt[1 << 10], num[1 << 10]; char s0[ma...

Kevin的博客 188

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

POJ 3074 Sudoku

Sudoku Time Limit: 1000MS Memory Limit: 65536K Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgrids. For example, . 2 7 3 8 . . 1 . . 1 . . . 6 7 3 ...

忘梦心的博客 1078

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

POJ3074 Sudoku —— Dancing Links 精确覆盖

题目链接:http://poj.org/problem?id=3074 Sudoku Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10451   Accepted: 3776 Description In the game of Sud

A man can be destroyed, but not defeated. 637

【poj3074】【DLX】sudoku

就是数独 Sudoku Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9617 Accepted: 3473 Description In the game of Sudoku, you are given a large 9 × 9 grid divided into

anantheparty的博客 553

POJ - 3074 Sudoku

Sudoku Time Limit:1000MS Memory Limit:65536K Total Submissions:10881 Accepted:3896 Description In the game of Sudoku, you are given a large 9 × 9 grid divide...

aiba481424的专栏 147

Sudoku POJ - 3074

dfs #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=9; int ones[1<<N],map[1<<N]; int row[N],col[N],cell[3][3]; char str[100]; in...

weixin_45113721的博客 214

POJ 3074 Sudoku 解题报告(Dancing Link)

Sudoku Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7878   Accepted: 2792 Description In the game of Sudoku, you are given a large 9 × 9 grid divided

SF-_- 的 ACM 博客 1163

poj 3074 Sudoku

坑爹的数独呀!又是搜索,又是剪枝~~~ 代码如下: #include #include #include const int MAX_COLOUMN=81+9*9+9*9+9*9+2; const int MAX_ROW=81*9+2; int cnt[MAX_COLOUMN

美文的ACM 794

Poj 3074: Sudoku

Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgrids. For example, . 2 7 3 8 . . 1 . . 1 . . . 6 7 3 5 . .

wxh010910 523

POJ 3074 Sudoku 【DLX】

题目来源:http://poj.org/problem?id=3074 ★我是真滴菜,这题又搞了三天,最后又是一个小细节问题。但愿这次之后真正理解了舞蹈链 题意: 有一个9x9的矩阵,有些位置的数字已经确定了下来,但还有很多地方没确定。现在你要找到一个满足如下条件的填数字的方法,然后输入最终填完的矩阵 ①:每个单元有且仅有一个数字 ②:每一列包含了1-9的9个数字 ③:每一行包含了1-9的9个...

HungTeen的博客 354

poj2676 2918 3074 3076 Sudoku

poj 2676题意:数独思路:1.dancing link2. dfs(填写每一个九宫格) 加剪枝 回溯  排除已出现的数字( sqr line column)  收缩顺序 优先选取已知数字较多的方块搜索#include &lt;iostream&gt; #include&lt;cstring&gt; #include &lt;cstdio&gt; #define mem(a) memset(a...

KLChen的博客 270
上一篇: HUST1017----Exact cover
下一篇: hdu4027----Can you answer these queries?
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值