Skip to content

Commit 67069f9

Browse files
committed
update
1 parent e59e097 commit 67069f9

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Time: 499 ms
2+
// Memory: 1400 KB
3+
// 只有0,1,2 三种答案,如果有正整数区间内包含0的子数组,答案就是2次。
4+
// T:O(sum(ni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1696B_NIT_Destroys_the_Universe {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt();
12+
for (int i = 0; i < t; i++) {
13+
int n = sc.nextInt(), ret = 0;
14+
int firstPosiIndex = -1, lastPosiIndex = -1, zeroIndex = -1;
15+
for (int j = 0; j < n; j++) {
16+
int a = sc.nextInt();
17+
if (a > 0) {
18+
if (firstPosiIndex == -1) {
19+
firstPosiIndex = j;
20+
if (j == n - 1) {
21+
lastPosiIndex = j;
22+
}
23+
} else {
24+
lastPosiIndex = Math.max(lastPosiIndex, j);
25+
}
26+
} else {
27+
if (firstPosiIndex != -1 && zeroIndex == -1) {
28+
zeroIndex = j;
29+
}
30+
}
31+
}
32+
33+
if (firstPosiIndex == -1) {
34+
ret = 0;
35+
} else if (firstPosiIndex == lastPosiIndex || zeroIndex == -1 || zeroIndex > lastPosiIndex) {
36+
ret = 1;
37+
} else {
38+
ret = 2;
39+
}
40+
41+
System.out.println(ret);
42+
}
43+
}
44+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Time: 265 ms
2+
// Memory: 800 KB
3+
// brute-force.
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1904A_Forked {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt();
12+
for (int i = 0; i < t; i++) {
13+
int a = sc.nextInt(), b = sc.nextInt(), x1 = sc.nextInt(), y1 = sc.nextInt(), x2 = sc.nextInt(),
14+
y2 = sc.nextInt(), ret = 0;
15+
int[][] moves;
16+
if (a == b) {
17+
moves = new int[][]{
18+
new int[]{a, b},
19+
new int[]{a, -b},
20+
new int[]{-a, b},
21+
new int[]{-a, -b}
22+
};
23+
} else {
24+
moves = new int[][]{
25+
new int[]{a, b},
26+
new int[]{a, -b},
27+
new int[]{-a, b},
28+
new int[]{-a, -b},
29+
new int[]{b, a},
30+
new int[]{b, -a},
31+
new int[]{-b, a},
32+
new int[]{-b, -a}
33+
};
34+
}
35+
for (int[] move : moves) {
36+
int x0 = move[0] + x1, y0 = move[1] + y1, xDiff = Math.abs(x0 - x2), yDiff = Math.abs(y0 - y2);
37+
if ((xDiff == a && yDiff == b) || (xDiff == b && yDiff == a)) {
38+
ret++;
39+
}
40+
}
41+
42+
System.out.println(ret);
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)