diff --git a/calc.js b/calc.js index dd61a6c..dee668f 100644 --- a/calc.js +++ b/calc.js @@ -155,6 +155,21 @@ function Solve(arr, num) { dfs(0); + // Sort res by the number of distinct elements in each matrix, in descending order + // If the number of distinct elements is the same, sort by the highest number in l for each element used in A and B + res.sort((A, B) => { + let distinctA = new Set(A.flat()).size; + let distinctB = new Set(B.flat()).size; + + if (distinctA !== distinctB) { + return distinctB - distinctA; + } else { + let maxA = Math.max(...A.flat().map(x => l[x-1])); + let maxB = Math.max(...B.flat().map(x => l[x-1])); + return maxB - maxA; + } + }); + return res; } diff --git a/calc.min.js b/calc.min.js index c355405..5b02045 100644 --- a/calc.min.js +++ b/calc.min.js @@ -1 +1 @@ -"use strict";function Solve(r,e){res=[],m=r.length,n=r[0].length,a=new Array(m);for(var o=0;o=m||e+i>=n||-1!==a[r+c][e+i]))return!1;return!0}function placeBlock(r,n,e,o,l){for(var t=blocks[e][o],f=0;!t[0][f];)++f;n-=f;for(var c=0;c=1e4&&(alert("方案数太多,仅计算前一万种。减少一些方块吧~"),!0)}var t=Math.floor(r/n),f=r%n;if(-1!==a[t][f])return!!dfs(r+1);for(var c=0;ce));return l=t.map((e=>e)),dfs(0),res.sort(((e,t)=>{let n=new Set(e.flat()).size,r=new Set(t.flat()).size;if(n!==r)return r-n;{let n=Math.max(...e.flat().map((e=>l[e-1])));return Math.max(...t.flat().map((e=>l[e-1])))-n}})),res}function canPlaceBlock(e,t,l,r){const o=blocks[l][r];let f=0;for(;!o[0][f];)++f;if((t-=f)<0)return!1;for(let l=0;l=m||t+r>=n||-1!==a[e+l][t+r]))return!1;return!0}function placeBlock(e,t,l,n,r){const o=blocks[l][n];let f=0;for(;!o[0][f];)++f;t-=f;for(let l=0;le));return res.push(e),res.length>=1e4&&(alert("方案数太多,仅计算前一万种。减少一些方块吧~"),!0)}const t=Math.floor(e/n),r=e%n;if(-1!==a[t][r])return!!dfs(e+1);for(let n=0;n