Skip to content

Commit a0023db

Browse files
committed
update
1 parent 62ba164 commit a0023db

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Time: 890 ms
2+
// Memory: 6200 KB
3+
// Sort & Greedy.
4+
// T:O(n), S:O(n)
5+
//
6+
import java.util.ArrayList;
7+
import java.util.Arrays;
8+
import java.util.Collections;
9+
import java.util.List;
10+
import java.util.Scanner;
11+
12+
public class Codeforces_1593C_Stable_Groups {
13+
public static void main(String[] args) {
14+
Scanner sc = new Scanner(System.in);
15+
int n = sc.nextInt();
16+
long k = sc.nextLong(), x = sc.nextLong(), ret = 0;
17+
long[] arr = new long[n];
18+
for (int i = 0; i < n; i++) {
19+
arr[i] = sc.nextLong();
20+
}
21+
Arrays.sort(arr);
22+
List<Long> diffs = new ArrayList<>();
23+
for (int i = 0; i < n - 1; i++) {
24+
long diff = arr[i + 1] - arr[i];
25+
if (diff > x) {
26+
diffs.add(diff);
27+
}
28+
}
29+
if (diffs.size() > 0) {
30+
Collections.sort(diffs);
31+
for (long diff : diffs) {
32+
long extra = (diff % x == 0 ? diff / x : (diff / x + 1)) - 1;
33+
if (extra <= k) {
34+
k -= extra;
35+
} else {
36+
ret++;
37+
}
38+
}
39+
}
40+
41+
System.out.println(ret + 1);
42+
}
43+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Time: 265 ms
2+
// Memory: 100 KB
3+
// Game: 偶数距离,先手必赢。只需先将距离缩小,后跟着对手的方向走即可。
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2055A_Two_Frogs {
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(), a = sc.nextInt(), b = sc.nextInt();
14+
System.out.println((a - b) % 2 == 0 ? "YES" : "NO");
15+
}
16+
}
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Time: 249 ms
2+
// Memory: 1000 KB
3+
// Math.
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2063A_Minimal_Coprime {
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 l = sc.nextInt(), r = sc.nextInt(), ret = 0;
14+
if (l == 1 && r == 1) {
15+
ret = 1;
16+
} else {
17+
ret = r - l;
18+
}
19+
20+
System.out.println(ret);
21+
}
22+
}
23+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Runtime 1 ms Beats 100.00%
2+
// Memory 42.36 MB Beats 100.00%
3+
// .
4+
// T:O(n), S:O(1)
5+
//
6+
class Solution {
7+
public boolean hasSpecialSubstring(String s, int k) {
8+
char prev = ' ';
9+
int len = s.length(), count = 0;
10+
for (int i = 0; i < len; i++) {
11+
char c = s.charAt(i);
12+
if (prev == ' ') {
13+
count++;
14+
if (k == count && (i + 1 >= len || (i + 1 < len && s.charAt(i + 1) != c))) {
15+
return true;
16+
}
17+
} else if (prev == c) {
18+
count++;
19+
if (k == count && (i + 1 >= len || i + 1 < len && s.charAt(i + 1) != c)) {
20+
return true;
21+
}
22+
} else {
23+
count = 1;
24+
if (k == count && (i + 1 >= len || i + 1 < len && s.charAt(i + 1) != c)) {
25+
return true;
26+
}
27+
}
28+
29+
prev = c;
30+
}
31+
32+
return false;
33+
}
34+
}

0 commit comments

Comments
 (0)