Sudoku Extension UVALive - 4763
//1 数字非0->跳过
//2 0 进入模式搜索
//3 o 进入奇数搜索
//4 e 进入偶数搜索
//5 其他alp字符 找之前记录的数字 如果没有重新搜索一个新数字
#include<bits/stdc++.h>
using namespace std;
char p[12][12];
int ans[12][12],c;// 结果矩阵
bool bok[12][10];//9 个正方形 每个里面有1-9
int aph[30];
void dfs(int x,int y);
void next(int x,int y)
{if(y<8&&x<=8)dfs(x,y+1);else if(y==8&&x<8)dfs(x+1,0);else if(y==8&&x==8){c++;return;}
}
bool check(int x,int y,int n)
{for(int i=0;i<9;i++)if(ans[x][i]==n)return 0;for(int i=0;i<9;i++)if(ans[i][y]==n)return 0;return 1;
}
void dfs(int x,int y)
{ int d = x/3*3+y/3;if(p[x][y]=='0'){for(int i=1;i<10;i++){if(check(x,y,i)&&!bok[d][i]){// 检查同行同列 和矩阵标记信息bok[d][i]=1;ans[x][y]=i;next(x,y);bok[d][i]=0;ans[x][y]=0;}}}else if(p[x][y]=='e'){for(int i=2;i<10;i+=2){if(check(x,y,i)&&!bok[d][i]){bok[d][i]=1;ans[x][y]=i;next(x,y);bok[d][i]=0;ans[x][y]=0;}}}else if(p[x][y]=='o'){for(int i=1;i<10;i+=2){if(check(x,y,i)&&!bok[d][i]){bok[d][i]=1;ans[x][y]=i;next(x,y);bok[d][i]=0;ans[x][y]=0;}}}else if(islower(p[x][y])){int t = p[x][y]-'a';if(aph[t]==0){// 如果没放过for(int i=1;i<10;i++)if(!bok[d][i]&&check(x,y,i)){bok[d][i]=1;ans[x][y] = i;aph[t]=i;next(x,y);aph[t]=0;bok[d][i]=0;ans[x][y] = 0;} }else {//放过if(!bok[d][aph[t]]&&check(x,y,aph[t])){//可行ans[x][y]=aph[t];bok[d][aph[t]]=1;next(x,y);bok[d][aph[t]]=0;ans[x][y] = 0; } else return;//不可行}}else next(x,y);
}
int main()
{int t;cin>>t;getchar();while(t--){ c=0;memset(bok,0,sizeof(bok));memset(ans,0,sizeof(ans));memset(aph,0,sizeof(aph));for(int i=0;i<9;i++){for(int j=0;j<9;j++){scanf("%c",&p[i][j]); int d = i/3*3+j/3;if(p[i][j]!='0'&&isdigit(p[i][j])){ans[i][j]=p[i][j]-'0';bok[d][p[i][j]-'0']=1;}} getchar();} dfs(0,0);cout<<c<<endl;}return 0;
}
Sudoku Extension UVALive - 4763相关推荐
- UVALive 3351 Easy and Not Easy Sudoku Puzzles 位运算~判断简单数独
题意:给定一个9*9的数独,要求判断是否为简单数独. 数独:对于每一行每一列或者子方格内,只能填1~9这几个数,并且每个数字只能出现一次,比如说: 如果一个9*9的数独是简单数独的话,这个数独的解是独 ...
- TVM apps extension示例扩展库
TVM apps extension示例扩展库 此文件夹包含TVM的示例扩展库.演示了其它库如何在C++和Python API中扩展TVM. 该库扩展了TVM的功能. python模块加载新的共享库, ...
- DP UVALive 6506 Padovan Sequence
题目传送门 /*题意:两行数字,相邻列一上一下,或者隔一列两行都可以,从左到右选择数字使和最大DP:状态转移方程:dp[i][j] = max (dp[i][j], dp[1-i][j-1] + a[ ...
- ios share extension 真机不显示_ios企业签名:APPGroups实现App之间数据共享
一.认识App Groups AppGroup allows data sharing between two different apps or even app and widgets by cr ...
- php解决 mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysq
微信小程序开发交流qq群 173683895 承接微信小程序开发.扫码加微信. The mysql extension is deprecated and will be removed i ...
- 解决 The mysql extension is deprecated and will be r
为什么80%的码农都做不了架构师?>>> 解决 The mysql extension is deprecated and will be removed in the fut ...
- Chrome Restful Api 测试工具 Postman-REST-Client离线安装包下载,Axure RP Extension for Chrome离线版下载...
[Postman for Chrome 离线下载] Postman-REST-Client离线安装包,可直接在Chrome浏览器本地安装使用,可模拟各种http请求,Restful Api测试, CS ...
- Chrome Extension 检查视图(无效)处理方法
最近闲来无事,简单看了下Chrome扩展的开发,并且开发一个小小的翻译插件(TranslateBao)作为练手,开发细节不详述了,如果有新学习chrome extension开发的新人,可以参考源码, ...
- Valid Sudoku leetcode java
题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...
最新文章
- 关于页面莫名空白的解决方式
- 安装python3.7.0的步骤_CentOS7下简单安装python3.7.0步骤
- realloc函数使用总结
- IText 生成页脚页码
- QEBA:基于类边界查询访问的黑盒攻击
- 阿里公开自研AI集群细节:64个GPU,百万分类训练速度提升4倍
- 弹窗设计UI素材模板|带你了解下弹窗特性
- Restorator软件使exe文件都不能打开,exe不支持此接口
- java处理代码表_Java处理中华人民共和国行政区划代码
- 基于HTML5、JavaScript和CSS3的网页开发应用技术的网页
- 前端应用 - 汉字笔顺书写演示带拼音及发音
- 秒懂HTTPS接口(原理篇)
- 大数据学习——常用的数据分析法和模型
- 第二章第三节(上)路径决策算法(动态规划)
- 阿里云国际版设置DNS托管和智能分流教程详解
- php 递归删目录和文件,php递归删除目录与文件的方法
- 中国移动和中国联通无线上网和资费详细
- php制作云端网盘项目,用云开发整一个专属网盘,原来如此简单!
- 联想ideapad 700 加固态(三星pm981)
- 关于php的设计模式
热门文章
- 对自己有用的VS调试技巧
- poj 1161 最短路构图
- oracle索引使用例子,Oracle中利用函数索引处理数据倾斜案例
- linux mate eth0已下线,Linux Mint 18 Cinnamon 版和 MATE 版已经可以下载了
- JavaScript this 关键字
- ssh WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
- word2007鼠标不好用
- java 数组地图绘画_Java将地图转换为数组[Snippet]
- matlab 8.4,《DSP using MATLAB》Problem 8.42
- hubbledotnet mysql_HubbleDotNet 简介