Skip to content

Commit d69efbc

Browse files
committed
update
1 parent 81b89e5 commit d69efbc

7 files changed

Lines changed: 193 additions & 0 deletions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// AC: 312 ms
2+
// Memory: 1400 KB
3+
// .
4+
// T:O(n), S:O(n)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_0680B_Bear_and_Finding_Criminals {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int n = sc.nextInt(), a = sc.nextInt(), ret = 0;
12+
int[] arr = new int[n];
13+
for (int i = 0; i < n; i++) {
14+
int x = sc.nextInt();
15+
arr[i] = x;
16+
}
17+
ret += arr[a - 1] == 1 ? 1 : 0;
18+
for (int i = 1; i <= n - 1; i++) {
19+
int left = (a - 1 - i) >= 0 ? arr[a - 1 - i] : -1, right = (a - 1 + i) < n ? arr[a - 1 + i] : -1;
20+
if (left == -1 && right == -1) {
21+
break;
22+
} else if (left == -1) {
23+
ret += right;
24+
} else if (right == -1) {
25+
ret += left;
26+
} else {
27+
ret += left == 1 && right == 1 ? 2 : 0;
28+
}
29+
}
30+
31+
System.out.println(ret);
32+
}
33+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// AC: 311 ms
2+
// Memory: 2300 KB
3+
// Math: 不管怎么转,最后 r,g,b,w 最多只能有一个奇数,而奇数次 operation 才会改变此格局.
4+
// 所以至多尝试一次,看能否使其至多有一个奇数
5+
// T:O(t), S:O(1)
6+
//
7+
import java.util.Scanner;
8+
9+
public class Codeforces_1395A_Boboniu_Likes_to_Color_Balls {
10+
public static void main(String[] args) {
11+
Scanner sc = new Scanner(System.in);
12+
int t = sc.nextInt();
13+
for (int i = 0; i < t; i++) {
14+
int r = sc.nextInt(), g = sc.nextInt(), b = sc.nextInt(), w = sc.nextInt();
15+
boolean ret = false;
16+
int countOdd = 0;
17+
countOdd += r % 2 == 1 ? 1 : 0;
18+
countOdd += g % 2 == 1 ? 1 : 0;
19+
countOdd += b % 2 == 1 ? 1 : 0;
20+
countOdd += w % 2 == 1 ? 1 : 0;
21+
if (countOdd <= 1) {
22+
ret = true;
23+
} else {
24+
if (r >= 1 && g >= 1 && b >= 1) {
25+
w += 3;
26+
r--;
27+
g--;
28+
b--;
29+
countOdd = 0;
30+
countOdd += r % 2 == 1 ? 1 : 0;
31+
countOdd += g % 2 == 1 ? 1 : 0;
32+
countOdd += b % 2 == 1 ? 1 : 0;
33+
countOdd += w % 2 == 1 ? 1 : 0;
34+
if (countOdd <= 1) {
35+
ret = true;
36+
}
37+
}
38+
}
39+
40+
System.out.println(ret ? "Yes" : "No");
41+
}
42+
}
43+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// AC: 358 ms
2+
// Memory: 1400 KB
3+
// Geometry: must be 2 * i^2 or 4 * i^2.
4+
// T:O(sum(logni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1515B_Phoenix_and_Puzzle {
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();
14+
boolean flag = false;
15+
if (n > 1 && n % 2 == 0) {
16+
int sqrtN = (int) Math.sqrt(n / 2);
17+
flag = sqrtN * sqrtN == n / 2;
18+
19+
if (!flag && n % 4 == 0) {
20+
sqrtN = (int) Math.sqrt(n / 4);
21+
flag = sqrtN * sqrtN == n / 4;
22+
}
23+
}
24+
25+
System.out.println(flag ? "YES" : "NO");
26+
}
27+
}
28+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// AC: 343 ms
2+
// Memory: 1100 KB
3+
// String: Can prove that if s[0] == s[s.length() - 1], then always have 'ab','ba' same occurence.
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1606A_AB_Balance {
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+
String s = sc.next();
14+
if (s.length() > 1 && s.charAt(0) != s.charAt(s.length() - 1)) {
15+
s = s.charAt(s.length() - 1) + s.substring(1);
16+
}
17+
18+
System.out.println(s);
19+
}
20+
}
21+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Runtime 13 ms Beats 26.67%
2+
// Memory 46.28 MB Beats 21.89%
3+
// Convert to Integer & sort. Notice the head and tail difference should also be included.
4+
// T:O(n), S:O(n)
5+
//
6+
class Solution {
7+
public int findMinDifference(List<String> timePoints) {
8+
int ret = Integer.MAX_VALUE;
9+
List<Integer> toMinutes = new ArrayList<>();
10+
for (String timePoint : timePoints) {
11+
toMinutes.add(convert(timePoint));
12+
}
13+
Collections.sort(toMinutes);
14+
ret = 24 * 60 - (toMinutes.get(toMinutes.size() - 1) - toMinutes.get(0));
15+
for (int i = 0; i < toMinutes.size() - 1; i++) {
16+
ret = Math.min(ret, toMinutes.get(i + 1) - toMinutes.get(i));
17+
if (ret == 0) {
18+
break;
19+
}
20+
}
21+
22+
return ret;
23+
}
24+
25+
private int convert(String timePoint) {
26+
String[] arr = timePoint.split(":");
27+
return Integer.parseInt(arr[0]) * 60 + Integer.parseInt(arr[1]);
28+
}
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Runtime 1 ms Beats 100.00%
2+
// Memory 44.89 MB Beats 100.00%
3+
// .
4+
// T:O(n), S:O(n)
5+
//
6+
class Solution {
7+
public List<Integer> stableMountains(int[] height, int threshold) {
8+
List<Integer> ret = new ArrayList<>();
9+
for (int i = 1; i < height.length; i++) {
10+
if (height[i - 1] > threshold) {
11+
ret.add(i);
12+
}
13+
}
14+
15+
return ret;
16+
}
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Runtime 3 ms Beats 100.00%
2+
// Memory 44.90 MB Beats 100.00%
3+
// .
4+
// T:O(n), S:O(n)
5+
//
6+
class Solution {
7+
public int[] getSneakyNumbers(int[] nums) {
8+
List<Integer> ret = new LinkedList<>();
9+
HashSet<Integer> set1 = new HashSet<>();
10+
for (int num : nums) {
11+
if (!set1.add(num)) {
12+
ret.add(num);
13+
}
14+
}
15+
int[] retArr = new int[ret.size()];
16+
for (int i = 0; i < ret.size(); i++) {
17+
retArr[i] = ret.get(i);
18+
}
19+
20+
return retArr;
21+
}
22+
}

0 commit comments

Comments
 (0)