Skip to content

Commit 099fc88

Browse files
committed
feat: update lc problems
1 parent eb8b334 commit 099fc88

19 files changed

Lines changed: 207 additions & 180 deletions

File tree

solution/1700-1799/1728.Cat and Mouse II/README.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -604,126 +604,126 @@ func getPrevStates(gMouse, gCat [][]int, m, c, t int, ans [][][]int) [][]int {
604604

605605
```ts
606606
function canMouseWin(grid: string[], catJump: number, mouseJump: number): boolean {
607-
const m = grid.length
608-
const n = grid[0].length
607+
const m = grid.length;
608+
const n = grid[0].length;
609609

610-
let catStart = 0
611-
let mouseStart = 0
612-
let food = 0
610+
let catStart = 0;
611+
let mouseStart = 0;
612+
let food = 0;
613613

614-
const dirs = [-1, 0, 1, 0, -1]
614+
const dirs = [-1, 0, 1, 0, -1];
615615

616-
const gMouse: number[][] = Array.from({ length: m * n }, () => [])
617-
const gCat: number[][] = Array.from({ length: m * n }, () => [])
616+
const gMouse: number[][] = Array.from({ length: m * n }, () => []);
617+
const gCat: number[][] = Array.from({ length: m * n }, () => []);
618618

619619
for (let i = 0; i < m; i++) {
620620
for (let j = 0; j < n; j++) {
621-
const c = grid[i][j]
621+
const c = grid[i][j];
622622

623-
if (c === '#') continue
623+
if (c === '#') continue;
624624

625-
const v = i * n + j
625+
const v = i * n + j;
626626

627-
if (c === 'C') catStart = v
628-
else if (c === 'M') mouseStart = v
629-
else if (c === 'F') food = v
627+
if (c === 'C') catStart = v;
628+
else if (c === 'M') mouseStart = v;
629+
else if (c === 'F') food = v;
630630

631631
for (let d = 0; d < 4; d++) {
632-
const a = dirs[d]
633-
const b = dirs[d + 1]
632+
const a = dirs[d];
633+
const b = dirs[d + 1];
634634

635635
for (let k = 0; k <= mouseJump; k++) {
636-
const x = i + k * a
637-
const y = j + k * b
636+
const x = i + k * a;
637+
const y = j + k * b;
638638

639-
if (!(0 <= x && x < m && 0 <= y && y < n && grid[x][y] !== '#')) break
639+
if (!(0 <= x && x < m && 0 <= y && y < n && grid[x][y] !== '#')) break;
640640

641-
gMouse[v].push(x * n + y)
641+
gMouse[v].push(x * n + y);
642642
}
643643

644644
for (let k = 0; k <= catJump; k++) {
645-
const x = i + k * a
646-
const y = j + k * b
645+
const x = i + k * a;
646+
const y = j + k * b;
647647

648-
if (!(0 <= x && x < m && 0 <= y && y < n && grid[x][y] !== '#')) break
648+
if (!(0 <= x && x < m && 0 <= y && y < n && grid[x][y] !== '#')) break;
649649

650-
gCat[v].push(x * n + y)
650+
gCat[v].push(x * n + y);
651651
}
652652
}
653653
}
654654
}
655655

656656
function getPrevStates(m: number, c: number, t: number, ans: number[][][]): number[][] {
657-
const pt = t ^ 1
658-
const pre: number[][] = []
657+
const pt = t ^ 1;
658+
const pre: number[][] = [];
659659

660660
if (pt === 1) {
661661
for (const pc of gCat[c]) {
662-
if (ans[m][pc][1] === 0) pre.push([m, pc, pt])
662+
if (ans[m][pc][1] === 0) pre.push([m, pc, pt]);
663663
}
664664
} else {
665665
for (const pm of gMouse[m]) {
666-
if (ans[pm][c][0] === 0) pre.push([pm, c, pt])
666+
if (ans[pm][c][0] === 0) pre.push([pm, c, pt]);
667667
}
668668
}
669669

670-
return pre
670+
return pre;
671671
}
672672

673673
function calc(): number {
674-
const N = m * n
674+
const N = m * n;
675675

676676
const degree: number[][][] = Array.from({ length: N }, () =>
677-
Array.from({ length: N }, () => [0, 0])
678-
)
677+
Array.from({ length: N }, () => [0, 0]),
678+
);
679679

680680
const ans: number[][][] = Array.from({ length: N }, () =>
681-
Array.from({ length: N }, () => [0, 0])
682-
)
681+
Array.from({ length: N }, () => [0, 0]),
682+
);
683683

684684
for (let i = 0; i < N; i++) {
685685
for (let j = 0; j < N; j++) {
686-
degree[i][j][0] = gMouse[i].length
687-
degree[i][j][1] = gCat[j].length
686+
degree[i][j][0] = gMouse[i].length;
687+
degree[i][j][1] = gCat[j].length;
688688
}
689689
}
690690

691-
const q: number[][] = []
691+
const q: number[][] = [];
692692

693693
for (let i = 0; i < N; i++) {
694-
ans[food][i][1] = 1
695-
ans[i][food][0] = 2
696-
ans[i][i][1] = 2
697-
ans[i][i][0] = 2
698-
699-
q.push([food, i, 1])
700-
q.push([i, food, 0])
701-
q.push([i, i, 0])
702-
q.push([i, i, 1])
694+
ans[food][i][1] = 1;
695+
ans[i][food][0] = 2;
696+
ans[i][i][1] = 2;
697+
ans[i][i][0] = 2;
698+
699+
q.push([food, i, 1]);
700+
q.push([i, food, 0]);
701+
q.push([i, i, 0]);
702+
q.push([i, i, 1]);
703703
}
704704

705705
while (q.length) {
706-
const [mPos, cPos, t] = q.shift()!
707-
const currentAns = ans[mPos][cPos][t]
706+
const [mPos, cPos, t] = q.shift()!;
707+
const currentAns = ans[mPos][cPos][t];
708708

709709
for (const [pm, pc, pt] of getPrevStates(mPos, cPos, t, ans)) {
710710
if (pt === currentAns - 1) {
711-
ans[pm][pc][pt] = currentAns
712-
q.push([pm, pc, pt])
711+
ans[pm][pc][pt] = currentAns;
712+
q.push([pm, pc, pt]);
713713
} else {
714-
degree[pm][pc][pt]--
714+
degree[pm][pc][pt]--;
715715
if (degree[pm][pc][pt] === 0) {
716-
ans[pm][pc][pt] = currentAns
717-
q.push([pm, pc, pt])
716+
ans[pm][pc][pt] = currentAns;
717+
q.push([pm, pc, pt]);
718718
}
719719
}
720720
}
721721
}
722722

723-
return ans[mouseStart][catStart][0]
723+
return ans[mouseStart][catStart][0];
724724
}
725725

726-
return calc() === 1
726+
return calc() === 1;
727727
}
728728
```
729729

solution/1700-1799/1728.Cat and Mouse II/README_EN.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -584,126 +584,126 @@ func getPrevStates(gMouse, gCat [][]int, m, c, t int, ans [][][]int) [][]int {
584584

585585
```ts
586586
function canMouseWin(grid: string[], catJump: number, mouseJump: number): boolean {
587-
const m = grid.length
588-
const n = grid[0].length
587+
const m = grid.length;
588+
const n = grid[0].length;
589589

590-
let catStart = 0
591-
let mouseStart = 0
592-
let food = 0
590+
let catStart = 0;
591+
let mouseStart = 0;
592+
let food = 0;
593593

594-
const dirs = [-1, 0, 1, 0, -1]
594+
const dirs = [-1, 0, 1, 0, -1];
595595

596-
const gMouse: number[][] = Array.from({ length: m * n }, () => [])
597-
const gCat: number[][] = Array.from({ length: m * n }, () => [])
596+
const gMouse: number[][] = Array.from({ length: m * n }, () => []);
597+
const gCat: number[][] = Array.from({ length: m * n }, () => []);
598598

599599
for (let i = 0; i < m; i++) {
600600
for (let j = 0; j < n; j++) {
601-
const c = grid[i][j]
601+
const c = grid[i][j];
602602

603-
if (c === '#') continue
603+
if (c === '#') continue;
604604

605-
const v = i * n + j
605+
const v = i * n + j;
606606

607-
if (c === 'C') catStart = v
608-
else if (c === 'M') mouseStart = v
609-
else if (c === 'F') food = v
607+
if (c === 'C') catStart = v;
608+
else if (c === 'M') mouseStart = v;
609+
else if (c === 'F') food = v;
610610

611611
for (let d = 0; d < 4; d++) {
612-
const a = dirs[d]
613-
const b = dirs[d + 1]
612+
const a = dirs[d];
613+
const b = dirs[d + 1];
614614

615615
for (let k = 0; k <= mouseJump; k++) {
616-
const x = i + k * a
617-
const y = j + k * b
616+
const x = i + k * a;
617+
const y = j + k * b;
618618

619-
if (!(0 <= x && x < m && 0 <= y && y < n && grid[x][y] !== '#')) break
619+
if (!(0 <= x && x < m && 0 <= y && y < n && grid[x][y] !== '#')) break;
620620

621-
gMouse[v].push(x * n + y)
621+
gMouse[v].push(x * n + y);
622622
}
623623

624624
for (let k = 0; k <= catJump; k++) {
625-
const x = i + k * a
626-
const y = j + k * b
625+
const x = i + k * a;
626+
const y = j + k * b;
627627

628-
if (!(0 <= x && x < m && 0 <= y && y < n && grid[x][y] !== '#')) break
628+
if (!(0 <= x && x < m && 0 <= y && y < n && grid[x][y] !== '#')) break;
629629

630-
gCat[v].push(x * n + y)
630+
gCat[v].push(x * n + y);
631631
}
632632
}
633633
}
634634
}
635635

636636
function getPrevStates(m: number, c: number, t: number, ans: number[][][]): number[][] {
637-
const pt = t ^ 1
638-
const pre: number[][] = []
637+
const pt = t ^ 1;
638+
const pre: number[][] = [];
639639

640640
if (pt === 1) {
641641
for (const pc of gCat[c]) {
642-
if (ans[m][pc][1] === 0) pre.push([m, pc, pt])
642+
if (ans[m][pc][1] === 0) pre.push([m, pc, pt]);
643643
}
644644
} else {
645645
for (const pm of gMouse[m]) {
646-
if (ans[pm][c][0] === 0) pre.push([pm, c, pt])
646+
if (ans[pm][c][0] === 0) pre.push([pm, c, pt]);
647647
}
648648
}
649649

650-
return pre
650+
return pre;
651651
}
652652

653653
function calc(): number {
654-
const N = m * n
654+
const N = m * n;
655655

656656
const degree: number[][][] = Array.from({ length: N }, () =>
657-
Array.from({ length: N }, () => [0, 0])
658-
)
657+
Array.from({ length: N }, () => [0, 0]),
658+
);
659659

660660
const ans: number[][][] = Array.from({ length: N }, () =>
661-
Array.from({ length: N }, () => [0, 0])
662-
)
661+
Array.from({ length: N }, () => [0, 0]),
662+
);
663663

664664
for (let i = 0; i < N; i++) {
665665
for (let j = 0; j < N; j++) {
666-
degree[i][j][0] = gMouse[i].length
667-
degree[i][j][1] = gCat[j].length
666+
degree[i][j][0] = gMouse[i].length;
667+
degree[i][j][1] = gCat[j].length;
668668
}
669669
}
670670

671-
const q: number[][] = []
671+
const q: number[][] = [];
672672

673673
for (let i = 0; i < N; i++) {
674-
ans[food][i][1] = 1
675-
ans[i][food][0] = 2
676-
ans[i][i][1] = 2
677-
ans[i][i][0] = 2
678-
679-
q.push([food, i, 1])
680-
q.push([i, food, 0])
681-
q.push([i, i, 0])
682-
q.push([i, i, 1])
674+
ans[food][i][1] = 1;
675+
ans[i][food][0] = 2;
676+
ans[i][i][1] = 2;
677+
ans[i][i][0] = 2;
678+
679+
q.push([food, i, 1]);
680+
q.push([i, food, 0]);
681+
q.push([i, i, 0]);
682+
q.push([i, i, 1]);
683683
}
684684

685685
while (q.length) {
686-
const [mPos, cPos, t] = q.shift()!
687-
const currentAns = ans[mPos][cPos][t]
686+
const [mPos, cPos, t] = q.shift()!;
687+
const currentAns = ans[mPos][cPos][t];
688688

689689
for (const [pm, pc, pt] of getPrevStates(mPos, cPos, t, ans)) {
690690
if (pt === currentAns - 1) {
691-
ans[pm][pc][pt] = currentAns
692-
q.push([pm, pc, pt])
691+
ans[pm][pc][pt] = currentAns;
692+
q.push([pm, pc, pt]);
693693
} else {
694-
degree[pm][pc][pt]--
694+
degree[pm][pc][pt]--;
695695
if (degree[pm][pc][pt] === 0) {
696-
ans[pm][pc][pt] = currentAns
697-
q.push([pm, pc, pt])
696+
ans[pm][pc][pt] = currentAns;
697+
q.push([pm, pc, pt]);
698698
}
699699
}
700700
}
701701
}
702702

703-
return ans[mouseStart][catStart][0]
703+
return ans[mouseStart][catStart][0];
704704
}
705705

706-
return calc() === 1
706+
return calc() === 1;
707707
}
708708
```
709709

0 commit comments

Comments
 (0)