衡东网站制作网站制作价格情况

张小明 2026/1/10 14:56:57
衡东网站制作,网站制作价格情况,受欢迎的邢台做网站,小程序网站https://github.com/JozefJarosciak/TangramPuzzleSolver 是一个图形界面的俄罗斯方块覆盖问题求解器#xff0c;为了能够批量求解#xff0c;让DeepSeek提取其中的计算代码#xff0c;和字符串输入组成一个命令行工具。将附件javascript代码提取出与显示无关的后台计算代码…https://github.com/JozefJarosciak/TangramPuzzleSolver 是一个图形界面的俄罗斯方块覆盖问题求解器为了能够批量求解让DeepSeek提取其中的计算代码和字符串输入组成一个命令行工具。将附件javascript代码提取出与显示无关的后台计算代码读入一行 矩形长度矩形宽度[形状编号A、B、C、D、I、L等数量 ]列表有解则输出填充了形状编号的矩阵无解提示无解他完全理解了需求输出代码如下。// block_solver_core.js// 俄罗斯方块覆盖问题求解器 - 核心计算模块// // 配置常量// // 方块形状定义constBLOCKS{A:[// Monomino (1x1)[[1]]],B:[// Domino (2x1)[[1,1]],// Horizontal[[1],[1]]// Vertical],C:[// Triomino I (3x1)[[1,1,1]],// Horizontal[[1],[1],[1]]// Vertical],D:[// Triomino L[[1,0],[1,1]],[[0,1],[1,1]],[[1,1],[1,0]],[[1,1],[0,1]]],I:[// Tetromino I (4x1)[[1,1,1,1]],[[1],[1],[1],[1]]],L:[// Tetromino L[[1,1,1],[1,0,0]],[[1,0],[1,0],[1,1]],[[0,0,1],[1,1,1]],[[1,1],[0,1],[0,1]]],O:[// Tetromino O (2x2)[[1,1],[1,1]]],S:[// Tetromino S[[0,1,1],[1,1,0]],[[1,0],[1,1],[0,1]]],T:[// Tetromino T[[1,1,1],[0,1,0]],[[0,1,0],[1,1,1]],[[1,0],[1,1],[1,0]],[[0,1],[1,1],[0,1]]],U:[// Pentomino U[[1,0,1],[1,1,1]],[[1,1,1],[1,0,1]],[[1,1],[1,0],[1,1]],[[1,1],[0,1],[1,1]]],X:[// Pentomino X[[0,1,0],[1,1,1],[0,1,0]]]};// 方块尺寸映射constBLOCK_SIZES{A:1,B:2,C:3,D:3,I:4,L:4,O:4,S:4,T:4,U:5,X:5};// // 工具函数// /** * 打乱数组顺序 * param {Array} array - 要打乱的数组 */functionshuffle(array){for(letiarray.length-1;i0;i--){constjMath.floor(Math.random()*(i1));[array[i],array[j]][array[j],array[i]];}}/** * 水平翻转形状 * param {ArrayArraynumber} shape - 原始形状 * returns {ArrayArraynumber} - 翻转后的形状 */functionreflectShape(shape){returnshape.map(row[...row].reverse());}/** * 获取方块在网格上的所有可能放置位置 * param {ArrayArraynumber} shape - 方块形状 * param {number} gridWidth - 网格宽度 * param {number} gridHeight - 网格高度 * returns {ArrayArraystring} - 所有可能的放置位置每个位置是一个单元格坐标数组 */functiongetAllPlacements(shape,gridWidth,gridHeight){if(!shape||shape.length0){return[];}constplacements[];constblockHeightshape.length;constblockWidthshape[0].length;for(lety0;ygridHeight-blockHeight;y){for(letx0;xgridWidth-blockWidth;x){constcells[];for(leti0;iblockHeight;i){for(letj0;jblockWidth;j){if(shape[i][j]1){cells.push(${yi},${xj});}}}placements.push(cells);}}returnplacements;}// // 舞蹈链算法实现// classDancingLinksNode{constructor(){this.leftthis;this.rightthis;this.upthis;this.downthis;this.columnnull;}}classColumnNodeextendsDancingLinksNode{constructor(name){super();this.namename;this.size0;this.columnthis;}/** * 覆盖这一列 */cover(){this.right.leftthis.left;this.left.rightthis.right;letithis.down;while(i!this){letji.right;while(j!i){j.down.upj.up;j.up.downj.down;j.column.size--;jj.right;}ii.down;}}/** * 恢复这一列 */uncover(){letithis.up;while(i!this){letji.left;while(j!i){j.column.size;j.down.upj;j.up.downj;jj.left;}ii.up;}this.right.leftthis;this.left.rightthis;}}classDataNodeextendsDancingLinksNode{constructor(column){super();this.columncolumn;}}classDancingLinksSolver{constructor(columns,maxTimeMs10000){this.headernewColumnNode(header);this.columns{};this.startTimeperformance.now();this.maxTimeMsmaxTimeMs;this.foundfalse;// 初始化列节点letlastthis.header;columns.forEach(colName{constcolumnnewColumnNode(colName);this.columns[colName]column;last.rightcolumn;column.leftlast;lastcolumn;});last.rightthis.header;this.header.leftlast;}/** * 搜索解 * param {number} k - 当前搜索深度 * param {Array} solution - 当前解决方案 * param {Array} solutions - 所有找到的解决方案 */search(k,solution,solutions){// 检查超时if(performance.now()-this.startTimethis.maxTimeMs){return;}// 如果所有列都被覆盖找到解if(this.header.rightthis.header){solutions.push([...solution]);this.foundtrue;return;}// 选择最小约束的列letminInfinity;letchosenColumnnull;lettmpthis.header.right;while(tmp!this.header){if(tmp.sizemin){mintmp.size;chosenColumntmp;}tmptmp.right;}if(chosenColumnnull||chosenColumn.size0){return;}chosenColumn.cover();// 收集该列的所有行letrowchosenColumn.down;constrows[];while(row!chosenColumn){rows.push(row);rowrow.down;}// 打乱行顺序以获得随机解shuffle(rows);for(leti0;irows.length!this.found;i){rowrows[i];solution.push(row);// 覆盖该行涉及的所有列letjrow.right;while(j!row){j.column.cover();jj.right;}// 递归搜索this.search(k1,solution,solutions);// 回溯solution.pop();jrow.left;while(j!row){j.column.uncover();jj.left;}}chosenColumn.uncover();}}// // 主要求解函数// /** * 解析输入字符串 * param {string} inputStr - 输入字符串格式width,height,[shape,count...] * returns {Object} - 解析后的参数对象 */functionparseInput(inputStr){// 移除所有空格constcleanedinputStr.replace(/\s/g,);// 匹配矩形尺寸constsizeMatchcleaned.match(/^(\d),(\d),\[/);if(!sizeMatch){thrownewError(输入格式错误: 应以 width,height,[ 开头);}constwidthparseInt(sizeMatch[1]);constheightparseInt(sizeMatch[2]);// 提取方块列表部分constlistMatchcleaned.match(/\[(.*)\]/);if(!listMatch){thrownewError(输入格式错误: 缺少方块列表);}constblockListStrlistMatch[1];constblockCounts{};// 解析方块列表constblockPattern/([A-Z]),(\d)/g;letmatch;lettotalArea0;while((matchblockPattern.exec(blockListStr))!null){constshapematch[1];constcountparseInt(match[2]);if(!BLOCKS[shape]){thrownewError(未知方块类型:${shape});}if(blockCounts[shape]){blockCounts[shape]count;}else{blockCounts[shape]count;}totalAreacount*(BLOCK_SIZES[shape]||0);}// 验证面积constgridAreawidth*height;if(totalArea!gridArea){thrownewError(面积不匹配: 网格面积${gridArea}, 方块总面积${totalArea});}return{width,height,blockCounts,totalBlocks:Object.values(blockCounts).reduce((a,b)ab,0)};}/** * 求解方块覆盖问题 * param {number} gridWidth - 网格宽度 * param {number} gridHeight - 网格高度 * param {Object} blockCounts - 方块数量映射 * returns {ArrayArraystring|null} - 解决方案矩阵无解返回null */functionsolveBlockPuzzle(gridWidth,gridHeight,blockCounts){// 生成列定义constcolumns[];// 单元格约束列for(lety0;ygridHeight;y){for(letx0;xgridWidth;x){columns.push(${y},${x});}}// 方块实例约束列for(letblockinblockCounts){for(leti0;iblockCounts[block];i){columns.push(${block}_${i});}}// 创建舞蹈链求解器constdlxnewDancingLinksSolver(columns);// 收集所有可能的放置方式constallPlacements[];for(letblockinblockCounts){for(letcount0;countblockCounts[block];count){// 原始方向BLOCKS[block].forEach(shape{constplacementsgetAllPlacements(shape,gridWidth,gridHeight);placements.forEach(cells{allPlacements.push({block,cells,count,shape});});});// 如果需要翻转添加翻转后的方向if([D,L,S,T,U].includes(block)){BLOCKS[block].forEach(shape{constmirroredreflectShape(shape);constplacementsgetAllPlacements(mirrored,gridWidth,gridHeight);placements.forEach(cells{allPlacements.push({block,cells,count,shape:mirrored});});});}}}// 打乱放置顺序以获得随机解shuffle(allPlacements);// 构建舞蹈链数据结构allPlacements.forEach(placement{constnodesInRow[];// 添加单元格约束节点placement.cells.forEach(cell{constcolNodedlx.columns[cell];if(!colNode)return;constnewNodenewDataNode(colNode);nodesInRow.push(newNode);newNode.upcolNode.up;newNode.downcolNode;colNode.up.downnewNode;colNode.upnewNode;colNode.size;});// 添加方块实例约束节点constblockInstance${placement.block}_${placement.count};constblockColNodedlx.columns[blockInstance];if(blockColNode){constnewNodenewDataNode(blockColNode);nodesInRow.push(newNode);newNode.upblockColNode.up;newNode.downblockColNode;blockColNode.up.downnewNode;blockColNode.upnewNode;blockColNode.size;}// 连接行内的节点nodesInRow.forEach((node,i){node.leftnodesInRow[i-1]||nodesInRow[nodesInRow.length-1];node.rightnodesInRow[i1]||nodesInRow[0];});});// 搜索解constsolutions[];dlx.search(0,[],solutions);if(solutions.length0){returnnull;}// 将第一个解转换为矩阵形式constsolutionMatrixArray(gridHeight).fill().map(()Array(gridWidth).fill(.));constsolutionsolutions[0];solution.forEach(rowNode{// 找到这个方块对应的单元格constblockCells[];letnoderowNode;do{if(node.column/\d,\d/.test(node.column.name)){blockCells.push(node.column.name);}nodenode.right;}while(node!rowNode);// 找到方块类型letblockTypenull;noderowNode;do{if(node.column/^[A-Z]_\d$/.test(node.column.name)){blockTypenode.column.name.split(_)[0];break;}nodenode.right;}while(node!rowNode);// 在矩阵中标记方块if(blockTypeblockCells.length0){blockCells.forEach(cell{const[y,x]cell.split(,).map(Number);if(y0ygridHeightx0xgridWidth){solutionMatrix[y][x]blockType;}});}});returnsolutionMatrix;}/** * 格式化输出矩阵 * param {ArrayArraystring} matrix - 解决方案矩阵 * returns {string} - 格式化后的字符串 */functionformatMatrix(matrix){returnmatrix.map(rowrow.join( )).join(\n);}// // 主函数命令行接口// /** * 命令行主函数 */functionmain(){// 判断是否在Node.js环境中if(typeofprocess!undefinedprocess.argv){// 从命令行参数读取输入if(process.argv.length3){console.log(用法: node block_solver_core.js width,height,[shape,count...]);console.log(示例: node block_solver_core.js 4,4,[A,4,B,6]);return;}constinputStrprocess.argv[2];try{// 解析输入const{width,height,blockCounts}parseInput(inputStr);console.log(求解${width}x${height}网格的方块覆盖问题...);console.log(方块配置:${JSON.stringify(blockCounts)});// 求解conststartTimeperformance.now();constsolutionsolveBlockPuzzle(width,height,blockCounts);constendTimeperformance.now();console.log(求解时间:${(endTime-startTime).toFixed(2)}ms);// 输出结果if(solution){console.log(\n找到解决方案:);console.log(formatMatrix(solution));}else{console.log(\n无解);}}catch(error){console.error(错误:,error.message);}}else{// 浏览器环境 - 提供测试接口console.log(方块覆盖求解器核心模块已加载);console.log(在Node.js环境中使用: node block_solver_core.js width,height,[shape,count...]);// 测试用例consttestCases[4,4,[A,4,B,6],// 4x4网格4个A方块6个B方块3,3,[A,9],// 3x3网格9个A方块2,4,[B,4],// 2x4网格4个B方块4,2,[I,2],// 4x2网格2个I方块4,5,[A,5,B,5,C,5]// 4x5网格各5个A,B,C方块];console.log(\n测试用例:);testCases.forEach(testCase{try{const{width,height,blockCounts}parseInput(testCase);constsolutionsolveBlockPuzzle(width,height,blockCounts);console.log(\n输入:${testCase});if(solution){console.log(有解);}else{console.log(无解);}}catch(error){console.log(\n输入:${testCase});console.log(错误:${error.message});}});}}// 如果直接运行此文件执行主函数if(typeofmodule!undefinedmodule.exports){module.exports{parseInput,solveBlockPuzzle,formatMatrix,BLOCKS,BLOCK_SIZES};// 如果通过命令行调用执行主函数if(require.mainmodule){main();}}// 浏览器环境直接执行if(typeofwindow!undefined){main();}用node.js执行结果如下node-v24.4.1-linux-x64/bin/node block_solver_core.js 4,4,[A,4,B,6] 求解 4x4 网格的方块覆盖问题... 方块配置: {A:4,B:6} 求解时间: 22.74ms 找到解决方案: B B B B B B B B B B B A A A B A node-v24.4.1-linux-x64/bin/node block_solver_core.js 3,3,[A,9] 求解 3x3 网格的方块覆盖问题... 方块配置: {A:9} 求解时间: 2.56ms 找到解决方案: A A A A A A A A A node-v24.4.1-linux-x64/bin/node block_solver_core.js 5,5,[O,1,X,1,U,2,L,2] 错误: 面积不匹配: 网格面积25, 方块总面积27也可以自定义形状实现任意形状的覆盖。
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

广西网站建设运营费用百度人气榜

很多想入门网络安全(俗称 “黑客技术”)的朋友,第一步就被 “英语门槛” 吓退了:“代码全是英文,工具界面也是英文,我英语差得一批,肯定学不会吧?” 其实这是最大的误解&#xff01…

张小明 2026/1/9 13:02:21 网站建设

网站代码有哪些手机网站的建设

VisualCppRedist AIO:Windows系统运行库终极解决方案 【免费下载链接】vcredist AIO Repack for latest Microsoft Visual C Redistributable Runtimes 项目地址: https://gitcode.com/gh_mirrors/vc/vcredist 你是否曾经遇到过这样的情况:安装某…

张小明 2026/1/4 11:19:57 网站建设

厦门市城乡建设局网站响应式网站区别

还在为APA格式的繁琐要求头疼吗?手动调整参考文献格式不仅耗时耗力,还容易出错。现在,这个开源工具能为你节省90%的排版时间,让你专注于内容创作本身! 【免费下载链接】APA-7th-Edition Microsoft Word XSD for genera…

张小明 2026/1/4 14:20:05 网站建设

营销型网站建设一般多少钱删负面的网站

Java 中的序列化与反序列化 序列化(Serialization)和反序列化(Deserialization)是 Java 中非常重要的概念,它们主要用于将对象转换成可以存储或传输的格式,或者将这种格式转换回原来的对象。 1. 什么是序…

张小明 2026/1/5 13:13:50 网站建设

dede茶叶网站模板怎样做一家网站

Windows 10 使用指南:应用探索、文件管理与平板操作技巧 在当今数字化的时代,Windows 10 操作系统凭借其强大的功能和广泛的用户基础,成为了众多用户的首选。本文将详细介绍 Windows 10 的多个使用方面,包括应用探索、文件管理以及在平板电脑上的使用技巧,帮助你更好地掌…

张小明 2026/1/5 22:14:38 网站建设

网站备案好后涪陵网站建设公司

从数据准备到模型输出:GPT-SoVITS全流程解析 在语音合成技术飞速发展的今天,我们正逐步告别千篇一律的“机器人朗读”。越来越多的应用开始追求个性化、情感化的表达——比如用你自己的声音给孩子的睡前故事配音,或是让视障人士以自己熟悉的声…

张小明 2026/1/5 18:47:46 网站建设