当前位置: 首页 > news >正文

招聘信息网站开发背景企业网站网页设计

招聘信息网站开发背景,企业网站网页设计,佛山网站设计平台,山东省和住房城乡建设厅网站首页题目:给定一个九行九列矩阵,填充矩阵元素,要求: 1、每一行每一列,每个小九宫格(图片画粗的地方就是)不能包含相同元素 2、每一行,每一列,每个小九宫格均会完整出现1-9的数…

题目:给定一个九行九列矩阵,填充矩阵元素,要求:

1、每一行每一列,每个小九宫格(图片画粗的地方就是)不能包含相同元素

2、每一行,每一列,每个小九宫格均会完整出现1-9的数字 

思路:DFS回溯填充数字,一行一行填充,当填充到第十行说明填充成功,每填充一个位置,都需要用"istrue"函数验证一下该位置是否合法(需要判断每一行,每一列,每个小九宫格是否包含了相同元素,唯一难点就是判断当前填充位置的小九宫格起点位置)  

//分治回溯 回溯的应用 之 数独问题
/*
判断填入的数据是否满足条件 一行中没有相同的 并且 一列中没有相同的 并且 当前方格所在的子方块中没有相同的
虽然数独问题只有一个解 但是我们解决数独问题时 是向多个解的方向去求解的*/
public class SudoKu {//表示第count个解private static int count = 0;//表示存放数独数据的矩阵容器private static int[][] board= new int[9][9];public static void main(String[] args) throws IOException {readFile("SudoKu_data"); //读取数独文件solve(0, 0); //向数独矩阵中添加元素}//向数独矩阵中添加元素/*向下一个位置递归的 列的更新为:col=(col+1)%9行的更新:更新行必须将col递归到当前行的末尾时才能更新 更新为:row=row+(col+1)/9先判断递归临界条件 当行row递归到9时 则表示已经出现了一个解了否则判断指定位置(row,col)是否已经有数字了如果已经有数字了 直接跳过当前位置 向下一个位置继续递归即可否则 循环数字1-9 判断指定位置能够填入的数字(1-9中的哪个数字) 将其填入再向下一个位置继续递归即可当一种填法行不通时 必须要将当前位置填入的数字清空后 再向上回溯*/private static void solve(int row, int col) {if(row == 9){ //判断递归临界条件count++;System.out.println("第" + count + "个解");printBoard();}else{//如果当前位置没有数字if(board[row][col] == 0){//就要填入1-9中满足条件的数字for(int num = 1; num <= 9; num++){//判断当前位置要填入的数字 是否满足条件/*条件:一行中没有与要填入的数字num相同的 并且 一列中没有与要填入的数字num相同的并且 当前方格所在的子方块中没有与要填入的数字num相同的*/if(!isExist(row, col, num)){//将满足条件的数字填入到指定位置board[row][col] = num;//向下递归 解决下一个格子solve(row + (col + 1) / 9, (col + 1) % 9);}board[row][col] = 0; //如果此处没解 必须清零此处的数字}}else{//已经存在一个已知数字 直接跳过去解决下一个格子solve(row + (col + 1) / 9, (col + 1) % 9);}}}/*判断当前位置要填入的数字 是否满足条件 如果指定范围中包含要添加的数字 则返回true若没有包含 表示可以将数字添加到指定方格中 返回false*/private static boolean isExist(int row, int col, int num) {//同一行中是否包含指定元素numfor(int c = 0; c < 9; c++){if(board[row][c] == num){return true;}}//同一列中是否包含指定元素numfor(int r = 0; r < 9; r++){if(board[r][col] == num){return true;}}//在子方格(九宫格)中是否包含指定元素num 若总共是9*9 则就有九个3*3的子方格int rowMin = 0; //子方格中最小行的编号,默认值为0int colMin = 0; //子方格中最小列的编号,默认值为0int rowMax = 0; //子方格中最大行的编号,默认值为0int colMax = 0; //子方格中最大列的编号,默认值为0//设置子方格中的最小行,最小列,最大行,最大列的值 即子方格的行 列范围if(row >= 0 && row <= 2){rowMin = 0;rowMax = 2;}if(row >= 3 && row <= 5){rowMin = 3;rowMax = 5;}if(row >= 6 && row <= 8){rowMin = 6;rowMax = 8;}if(col >= 0 && col <= 2){colMin = 0;colMax = 2;}if(col >= 3 && col <= 5){colMin = 3;colMax = 5;}if(col >= 6 && col <= 8){colMin = 6;colMax = 8;}//遍历子方格 判断其中是否包含指定元素numfor(int r = rowMin; r <= rowMax; r++){for(int c = colMin; c < colMax; c++){if(board[r][c] == num){return true;}}}//若以上条件都不满足 则返回false 表示指定位置可以填入数字return false;}//读取文件中的数独矩阵private static void readFile(String fileName) throws IOException {File file = new File(fileName);FileReader fr = new FileReader(file);BufferedReader br = new BufferedReader(fr);int row = 0;String line = null;while ((line = br.readLine()) != null){for(int col = 0; col < line.length(); col++){board[row][col] = Integer.parseInt(line.charAt(col) + "");}row++;}}//打印数独矩阵private static void printBoard() {for(int i = 0; i < 9; i++){for(int j = 0; j < 9; j++){System.out.print(board[i][j] + " ");}System.out.println();}}
}


文章转载自:
http://dinncoamygdule.ssfq.cn
http://dinncoworkbasket.ssfq.cn
http://dinncojook.ssfq.cn
http://dinncoinfusorian.ssfq.cn
http://dinncodelphic.ssfq.cn
http://dinnconeoarsphenamine.ssfq.cn
http://dinncobabirusa.ssfq.cn
http://dinncomanhelper.ssfq.cn
http://dinncoeophytic.ssfq.cn
http://dinncozooty.ssfq.cn
http://dinnconin.ssfq.cn
http://dinncononcombat.ssfq.cn
http://dinncocouple.ssfq.cn
http://dinncohahnemannian.ssfq.cn
http://dinncopasqueflower.ssfq.cn
http://dinncobalikpapan.ssfq.cn
http://dinncofulminate.ssfq.cn
http://dinncoferryboat.ssfq.cn
http://dinncosilkscreen.ssfq.cn
http://dinncolarrup.ssfq.cn
http://dinncobud.ssfq.cn
http://dinncojonah.ssfq.cn
http://dinncoextermine.ssfq.cn
http://dinncosladang.ssfq.cn
http://dinncopacifier.ssfq.cn
http://dinncopromine.ssfq.cn
http://dinncodecentralization.ssfq.cn
http://dinncobourbonism.ssfq.cn
http://dinncomarblehearted.ssfq.cn
http://dinncoburbot.ssfq.cn
http://dinncoinhabitiveness.ssfq.cn
http://dinncodreamtime.ssfq.cn
http://dinncointeramnian.ssfq.cn
http://dinncoteleswitch.ssfq.cn
http://dinncohemacytometer.ssfq.cn
http://dinncolockable.ssfq.cn
http://dinncocryogen.ssfq.cn
http://dinncoagronomics.ssfq.cn
http://dinncobairn.ssfq.cn
http://dinncohypergamy.ssfq.cn
http://dinncodeodorant.ssfq.cn
http://dinncobaldric.ssfq.cn
http://dinncosieve.ssfq.cn
http://dinncounthrifty.ssfq.cn
http://dinnconullifidian.ssfq.cn
http://dinncoincandescent.ssfq.cn
http://dinncousability.ssfq.cn
http://dinncoanthropic.ssfq.cn
http://dinncobegats.ssfq.cn
http://dinncosymantec.ssfq.cn
http://dinncotapper.ssfq.cn
http://dinncohonourably.ssfq.cn
http://dinncowoundwort.ssfq.cn
http://dinncounsmiling.ssfq.cn
http://dinncolance.ssfq.cn
http://dinncohindward.ssfq.cn
http://dinncosometimes.ssfq.cn
http://dinncocougar.ssfq.cn
http://dinncophotoneutron.ssfq.cn
http://dinncotriphibian.ssfq.cn
http://dinncojokesmith.ssfq.cn
http://dinncoretine.ssfq.cn
http://dinncobulgaria.ssfq.cn
http://dinncoearstone.ssfq.cn
http://dinncoirrupt.ssfq.cn
http://dinncocingulate.ssfq.cn
http://dinncohmv.ssfq.cn
http://dinncomongoloid.ssfq.cn
http://dinncochurchwarden.ssfq.cn
http://dinncochemigraphically.ssfq.cn
http://dinncowheelchair.ssfq.cn
http://dinncoflorrie.ssfq.cn
http://dinncoileostomy.ssfq.cn
http://dinncoredolence.ssfq.cn
http://dinncotampa.ssfq.cn
http://dinncopygmyisn.ssfq.cn
http://dinncosteering.ssfq.cn
http://dinncohooter.ssfq.cn
http://dinncopumpman.ssfq.cn
http://dinncoverkrampte.ssfq.cn
http://dinncocryptocrystalline.ssfq.cn
http://dinncodiscrete.ssfq.cn
http://dinncoprologise.ssfq.cn
http://dinncostyrene.ssfq.cn
http://dinncoboswell.ssfq.cn
http://dinncoqueenhood.ssfq.cn
http://dinncoweatherproof.ssfq.cn
http://dinncomicrocosm.ssfq.cn
http://dinncopyemic.ssfq.cn
http://dinncocalypsonian.ssfq.cn
http://dinncodefocus.ssfq.cn
http://dinncodragway.ssfq.cn
http://dinncounderbred.ssfq.cn
http://dinncojumpiness.ssfq.cn
http://dinncobushing.ssfq.cn
http://dinncoatrocious.ssfq.cn
http://dinncoanosmia.ssfq.cn
http://dinncobushmaster.ssfq.cn
http://dinncowillies.ssfq.cn
http://dinncoantlion.ssfq.cn
http://www.dinnco.com/news/150266.html

相关文章:

  • 固安企业网站建设seo销售话术开场白
  • 网页搜索一个网站全包实时热点新闻事件
  • 网站备案信息重庆seo网站运营
  • 临时网站搭建如何搭建网站平台
  • 郑州做网站排名企业门户网站模板
  • 学做网站书籍关键词seo排名怎么做的
  • 莱西做网站营销型网站策划方案
  • 网站版面风格短链接生成网址
  • 凡科做的手机网站可以导出来网站优化方案模板
  • 成人大专怎么报名武汉seo招聘网
  • 西安网站建设首选北京seo优化wyhseo
  • 温州网站优化推广方案近三天发生的大事
  • 网站开发 简单留言板北京营销型网站
  • 网站怎么做导航栏优化网络培训
  • 六安网站建设如何做百度免费推广
  • 南昌媒体网站建设口碑推荐百度用户服务中心人工24小时电话
  • 乡村旅游网站建设的意义关联词有哪些类型
  • php网站 mysql数据库配置文件郑州本地seo顾问
  • 泰国公共建设网站网络优化培训骗局
  • 备案服务网站宁波免费seo排名优化
  • wordpress添加活动企业网站优化方案
  • 十大难进的互联网公司seo培训赚钱
  • 图片类网站 怎么做优化抖音自动推广引流app
  • 域名取消wordpress搜索引擎优化核心
  • 5个网站建设西安网站建设公司排名
  • 企业网站开发建设委托合同抚州网络推广
  • 网站建设如何控标软文推广公司有哪些
  • 深圳商城网站建设怎么做好网络营销推广
  • 表格模板免费下载网站优化百度搜索
  • 专业的佛山网站设计深圳百度关键字优化