Skip to content

Commit

Permalink
order by varity
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan-Lee-Moran committed May 21, 2024
1 parent 05d905b commit e714828
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
15 changes: 15 additions & 0 deletions calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion calc.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>尘白禁区信源研析</title>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/3.2.47/vue.global.prod.min.js"></script>
<script src="./calc.min.js"></script>
<script src="./calc.js"></script>
</head>

<body>
Expand Down Expand Up @@ -77,6 +77,7 @@
},
calc() {
this.res = Solve(this.board, this.num)
console.log(this.res)
this.now = 0
}
},
Expand Down

0 comments on commit e714828

Please sign in to comment.