forked from CmdBlockZQG/cbjq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.min.js
1 lines (1 loc) · 1.5 KB
/
calc.min.js
1
const blocks=[[[[1,1],[1,1]]],[[[2,2,2,2]],[[2],[2],[2],[2]]],[[[3,3,0],[0,3,3]],[[0,3],[3,3],[3,0]]],[[[0,4,4],[4,4,0]],[[4,0],[4,4],[0,4]]],[[[5,0,0],[5,5,5]],[[5,5],[5,0],[5,0]],[[5,5,5],[0,0,5]],[[0,5],[0,5],[5,5]]],[[[0,0,6],[6,6,6]],[[6,6],[0,6],[0,6]],[[6,6,6],[6,0,0]],[[6,0],[6,0],[6,6]]],[[[0,7,0],[7,7,7]],[[7,7,7],[0,7,0]],[[7,0],[7,7],[7,0]],[[0,7],[7,7],[0,7]]],[[[0,8,0],[8,8,8],[0,8,0]]],[[[9]]],[[[10,10]],[[10],[10]]],[[[11,11],[11,0]],[[11,11],[0,11]],[[0,11],[11,11]],[[11,0],[11,11]]]];let m,n,a,l,res;function Solve(e,d){res=[];m=e.length;n=e[0].length;a=Array(m);for(let c=0;c<m;++c)a[c]=e[c].map(b=>b);l=d.map(c=>c);dfs(0);return res}function canPlaceBlock(e,d,c,b){c=blocks[c][b];for(b=0;!c[0][b];)++b;d-=b;if(0>d)return!1;for(b=0;b<c.length;++b)for(let f=0;f<c[0].length;++f)if(c[b][f]&&(e+b>=m||d+f>=n||-1!==a[e+b][d+f]))return!1;return!0}function placeBlock(e,d,c,b,f){c=blocks[c][b];for(b=0;!c[0][b];)++b;d-=b;for(b=0;b<c.length;++b)for(let g=0;g<c[0].length;++g)c[b][g]&&(a[e+b][d+g]=f)}function dfs(e){if(e===m*n){e=Array(m);for(var d=0;d<m;++d)e[d]=a[d].map(b=>b);res.push(e);return 1E4<=res.length?(alert("\u65b9\u6848\u6570\u592a\u591a\uff0c\u4ec5\u8ba1\u7b97\u524d\u4e00\u4e07\u79cd\u3002\u51cf\u5c11\u4e00\u4e9b\u65b9\u5757\u5427~"),!0):!1}d=Math.floor(e/n);const c=e%n;if(-1!==a[d][c])return dfs(e+1)?!0:!1;for(let b=0;b<blocks.length;++b)if(l[b])for(let f=0;f<blocks[b].length;++f)if(canPlaceBlock(d,c,b,f)){placeBlock(d,c,b,f,b+1);--l[b];if(dfs(e+1))return!0;++l[b];placeBlock(d,c,b,f,-1)}return!1}