From e5dd341fab18a704af2fa836da5336cbe808eb9b Mon Sep 17 00:00:00 2001 From: lolicon0930 <14966910+llc0930@users.noreply.github.com> Date: Wed, 19 Jun 2024 19:53:20 +0800 Subject: [PATCH 1/4] Dealing with CRLF issues --- calc.js | 466 ++++++++++++++++++++++++++--------------------------- index.html | 208 ++++++++++++------------ 2 files changed, 337 insertions(+), 337 deletions(-) diff --git a/calc.js b/calc.js index dee668f..d03c408 100644 --- a/calc.js +++ b/calc.js @@ -1,233 +1,233 @@ -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(arr, num) { - res = []; - m = arr.length; - n = arr[0].length; - - a = new Array(m); - for (let i = 0; i < m; ++i) { - a[i] = arr[i].map(x => x); - } - - l = num.map(x => x); - - 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; -} - -function canPlaceBlock(x, y, b, d) { - const pat = blocks[b][d]; - let offset = 0; - while (!pat[0][offset]) ++offset; - y -= offset; - if (y < 0) return false; - for (let i = 0; i < pat.length; ++i) { - for (let j = 0; j < pat[0].length; ++j) { - if (pat[i][j] && (x + i >= m || y + j >= n || a[x + i][y + j] !== -1)) return false; - } - } - return true; -} - -function placeBlock(x, y, b, d, v) { - const pat = blocks[b][d]; - let offset = 0; - while (!pat[0][offset]) ++offset; - y -= offset; - for (let i = 0; i < pat.length; ++i) { - for (let j = 0; j < pat[0].length; ++j) { - if (pat[i][j]) a[x + i][y + j] = v; - } - } -} - -function dfs(p) { - if (p === m * n) { - const x = new Array(m); - for (let i = 0; i < m; ++i) { - x[i] = a[i].map(x => x); - } - res.push(x); - if (res.length >= 10000) { - alert('方案数太多,仅计算前一万种。减少一些方块吧~'); - return true; - } - return false; - } - const x = Math.floor(p / n), y = p % n; - if (a[x][y] !== -1) { - if (dfs(p + 1)) return true; - return false; - } - for (let b = 0; b < blocks.length; ++b) { - if (!l[b]) continue; - for (let d = 0; d < blocks[b].length; ++d) { - if (!canPlaceBlock(x, y, b, d)) continue; - placeBlock(x, y, b, d, b + 1); - --l[b]; - if (dfs(p + 1)) return true; - ++l[b]; - placeBlock(x, y, b, d, -1); - } - } - return false; -} - +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(arr, num) { + res = []; + m = arr.length; + n = arr[0].length; + + a = new Array(m); + for (let i = 0; i < m; ++i) { + a[i] = arr[i].map(x => x); + } + + l = num.map(x => x); + + 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; +} + +function canPlaceBlock(x, y, b, d) { + const pat = blocks[b][d]; + let offset = 0; + while (!pat[0][offset]) ++offset; + y -= offset; + if (y < 0) return false; + for (let i = 0; i < pat.length; ++i) { + for (let j = 0; j < pat[0].length; ++j) { + if (pat[i][j] && (x + i >= m || y + j >= n || a[x + i][y + j] !== -1)) return false; + } + } + return true; +} + +function placeBlock(x, y, b, d, v) { + const pat = blocks[b][d]; + let offset = 0; + while (!pat[0][offset]) ++offset; + y -= offset; + for (let i = 0; i < pat.length; ++i) { + for (let j = 0; j < pat[0].length; ++j) { + if (pat[i][j]) a[x + i][y + j] = v; + } + } +} + +function dfs(p) { + if (p === m * n) { + const x = new Array(m); + for (let i = 0; i < m; ++i) { + x[i] = a[i].map(x => x); + } + res.push(x); + if (res.length >= 10000) { + alert('方案数太多,仅计算前一万种。减少一些方块吧~'); + return true; + } + return false; + } + const x = Math.floor(p / n), y = p % n; + if (a[x][y] !== -1) { + if (dfs(p + 1)) return true; + return false; + } + for (let b = 0; b < blocks.length; ++b) { + if (!l[b]) continue; + for (let d = 0; d < blocks[b].length; ++d) { + if (!canPlaceBlock(x, y, b, d)) continue; + placeBlock(x, y, b, d, b + 1); + --l[b]; + if (dfs(p + 1)) return true; + ++l[b]; + placeBlock(x, y, b, d, -1); + } + } + return false; +} + diff --git a/index.html b/index.html index 293ec8d..5482019 100644 --- a/index.html +++ b/index.html @@ -1,105 +1,105 @@ - - - - - - - 尘白禁区信源研析 - - - - - - Bilibili 方形的块状代码 -
-

行数:

-

列数:

- -

红色表示需要摆放的格子,白色表示这里没有格子,点击切换

-
-
-
-
-

方块{{ i + 1 }}个数:

- -
-
-

方案数:{{ res.length }}

-
-
-

当前展示方案:{{ now + 1 }} / {{ res.length }}

- - -
-
{{ c }}
-
-
-
- - - - + + + + + + + 尘白禁区信源研析 + + + + + + Bilibili 方形的块状代码 +
+

行数:

+

列数:

+ +

红色表示需要摆放的格子,白色表示这里没有格子,点击切换

+
+
+
+
+

方块{{ i + 1 }}个数:

+ +
+
+

方案数:{{ res.length }}

+
+
+

当前展示方案:{{ now + 1 }} / {{ res.length }}

+ + +
+
{{ c }}
+
+
+
+ + + + \ No newline at end of file From ba468a451326b11c66ed64cecef2a6f3e8eebedd Mon Sep 17 00:00:00 2001 From: lolicon0930 <14966910+llc0930@users.noreply.github.com> Date: Wed, 19 Jun 2024 20:02:55 +0800 Subject: [PATCH 2/4] Use maximum amount of fragment 8 and minimum amount of fragment 9 --- calc.js | 15 ------------ calc.min.js | 2 +- index.html | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 65 insertions(+), 19 deletions(-) diff --git a/calc.js b/calc.js index d03c408..b4dc1e0 100644 --- a/calc.js +++ b/calc.js @@ -155,21 +155,6 @@ 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 5b02045..85b853f 100644 --- a/calc.min.js +++ b/calc.min.js @@ -1 +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,t){res=[],m=e.length,n=e[0].length,a=new Array(m);for(let t=0;te));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;nb);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=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;bb);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 el) + num_n8[7] = 0 + + const board_8 = Solve(this.board, num_8) + let mapped = board_8.map((el, i) => { + return { index: i, value: (el.flat().filter(el => el === 8).length / 5) } + }) + mapped.sort((a, b) => b.value - a.value) + + let sorted = [] + let s_max8 = [] + let c_8 = mapped[0].value + while (c_8 >= 0) { + sorted = mapped.filter(el => el.value === c_8).map(el => board_8[el.index]) + for (let s = 0; s < sorted.length ; ++s) { + for (let r = 0; r < Number(this.row); ++r) { + sorted[s][r].forEach((el, i, arr) => { + if (arr[i] === 9) arr[i] = -1 + }) + } + let s_min9 = [] + for (let c_9 = 0; c_9 <= Number(this.num[8]); ++c_9) { + num_n8[8] = c_9 + s_min9 = s_min9.concat(Solve(sorted[s], num_n8)) + if (s_min9.length > 0) break + } + s_max8 = s_max8.concat(s_min9) + } + if (s_max8.length > 0) break + --c_8 + } + + // 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 + s_max8.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 => this.num[x-1])) + let maxB = Math.max(...B.flat().map(x => this.num[x-1])) + return maxB - maxA + } + }) + + //let c_nAB = 0 + s_max8.sort((a, b) => { + return (a.flat().filter(el => el === 10).length / 2 + a.flat().filter(el => el === 11).length / 3) - (b.flat().filter(el => el === 10).length / 2 + b.flat().filter(el => el === 11).length / 3) + }) + s_max8.sort((a, b) => a.flat().filter(el => el === 9).length - b.flat().filter(el => el === 9).length) + /*s_max8.forEach((el, i, arr) => { + if ( !(el.flat().includes(10)) && !(el.flat().includes(11)) ) ++c_nAB + })*/ + //console.log(c_nAB) + + this.res = s_max8 this.now = 0 } }, @@ -102,4 +163,4 @@ - \ No newline at end of file + From dc5cc27905fd3e47323471d88c9ccc5505186d99 Mon Sep 17 00:00:00 2001 From: lolicon0930 <14966910+llc0930@users.noreply.github.com> Date: Thu, 20 Jun 2024 20:19:15 +0800 Subject: [PATCH 3/4] Correct priority logic Corrected logic: Prioritize the use of fragments 10 and 11 that caused the number of solutions to soar. --- index.html | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 2494122..8a1a222 100644 --- a/index.html +++ b/index.html @@ -102,7 +102,19 @@ let s_min9 = [] for (let c_9 = 0; c_9 <= Number(this.num[8]); ++c_9) { num_n8[8] = c_9 - s_min9 = s_min9.concat(Solve(sorted[s], num_n8)) + let rf_base = Math.max(...num_n8.slice(0,-4)) + let s_rf = [] + for (let rf = 0; rf <= rf_base; ++rf) { + let num_rf = num_n8.map(el => el) + for (let i = 0; i < num_rf.length - 4; ++i) { + num_rf[i] -= (rf_base - rf) + if (num_rf[i] < 0) num_rf[i] = 0 + } + //console.log(num_rf) + s_rf = s_rf.concat(Solve(sorted[s], num_rf)) + if (s_rf.length > 0) break + } + s_min9 = s_min9.concat(s_rf) if (s_min9.length > 0) break } s_max8 = s_max8.concat(s_min9) @@ -127,15 +139,10 @@ } }) - //let c_nAB = 0 s_max8.sort((a, b) => { - return (a.flat().filter(el => el === 10).length / 2 + a.flat().filter(el => el === 11).length / 3) - (b.flat().filter(el => el === 10).length / 2 + b.flat().filter(el => el === 11).length / 3) + return (b.flat().filter(el => el === 10).length / 2 + b.flat().filter(el => el === 11).length / 3) - (a.flat().filter(el => el === 10).length / 2 + a.flat().filter(el => el === 11).length / 3) }) s_max8.sort((a, b) => a.flat().filter(el => el === 9).length - b.flat().filter(el => el === 9).length) - /*s_max8.forEach((el, i, arr) => { - if ( !(el.flat().includes(10)) && !(el.flat().includes(11)) ) ++c_nAB - })*/ - //console.log(c_nAB) this.res = s_max8 this.now = 0 From 689d7bdd0538507c7b99054513cc06e13a89c8b4 Mon Sep 17 00:00:00 2001 From: lolicon0930 <14966910+llc0930@users.noreply.github.com> Date: Mon, 1 Jul 2024 15:01:29 +0800 Subject: [PATCH 4/4] BootCDN badware risks --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 8a1a222..f92c368 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ 尘白禁区信源研析 - +