Skip to content

Commit 3ef1f83

Browse files
committed
feat: todo or to commit
1 parent f0bd287 commit 3ef1f83

26 files changed

+446
-0
lines changed

codeForces/Codeforces_1333A_Little_Artem.java

Whitespace-only changes.

codeForces/Codeforces_1382B_Sequential_Nim.java

Whitespace-only changes.

codeForces/Codeforces_1538C_Number_of_Pairs.java

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// AC: 249 ms
2+
// Memory: 900 KB
3+
// greedy.
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1955A_Yogurt_Sale {
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(), ret = 0;
14+
if (2 * a <= b) {
15+
ret = n * a;
16+
} else {
17+
ret = (n / 2) * b + (n % 2) * a;
18+
}
19+
System.out.println(ret);
20+
}
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// AC: 281 ms
2+
// Memory: 900 KB
3+
// Math: since 1 <= y < x, we can prove that gcd(x, y) + y <= x. Notice when y = x - 1,
4+
// the value of gcd(x, y) + y == x, so this is one of the answer.
5+
// T:O(t), S:O(1)
6+
//
7+
import java.util.Scanner;
8+
9+
public class Codeforces_1968A_Maximize {
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 x = sc.nextInt();
15+
16+
System.out.println(x - 1);
17+
}
18+
}
19+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// AC: 358 ms
2+
// Memory: 800 KB
3+
// Two pointers.
4+
// T:O(sum(mi + ni)), S:O(max(mi + ni))
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1968B_Prefiquence {
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(), m = sc.nextInt(), curPos = 0, ret = 0;
14+
String a = sc.next(), b = sc.next();
15+
for (int j = 0; j < n && curPos < m; j++) {
16+
char c = a.charAt(j);
17+
while (curPos < m && b.charAt(curPos) != c) {
18+
curPos++;
19+
}
20+
if (curPos < m && b.charAt(curPos) == c) {
21+
curPos++;
22+
ret++;
23+
}
24+
}
25+
26+
System.out.println(ret);
27+
}
28+
}
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// AC: 327 ms
2+
// Memory: 600 KB
3+
// .
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1971A_My_First_Sorting_Problem {
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 x = sc.nextInt(), y = sc.nextInt(), min = Math.min(x, y), max = Math.max(x, y);
14+
System.out.println(min + " " + max);
15+
}
16+
}
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// AC: 280 ms
2+
// Memory: 0 KB
3+
// .
4+
// T:O(sum(ni)), S:O(max(ni))
5+
//
6+
import java.util.HashMap;
7+
import java.util.Scanner;
8+
9+
public class Codeforces_1971B_Different_String {
10+
public static void main(String[] args) {
11+
Scanner sc = new Scanner(System.in);
12+
int t = sc.nextInt();
13+
HashMap<Character, Integer> record = new HashMap<>();
14+
for (int i = 0; i < t; i++) {
15+
String s = sc.next();
16+
for (char c : s.toCharArray()) {
17+
record.merge(c, 1, Integer::sum);
18+
}
19+
if (record.size() == 1) {
20+
System.out.println("NO");
21+
} else {
22+
System.out.println("YES");
23+
StringBuilder ret = new StringBuilder();
24+
for (char key : record.keySet()) {
25+
ret.append(String.valueOf(key).repeat(record.get(key)));
26+
}
27+
if (ret.toString().equals(s)) {
28+
ret.reverse();
29+
}
30+
System.out.println(ret);
31+
}
32+
record.clear();
33+
}
34+
}
35+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// AC: 296 ms
2+
// Memory: 700 KB
3+
// .
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1971C_Clock_and_Strings {
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(), c = sc.nextInt(), d = sc.nextInt();
14+
int min1 = Math.min(a, b), max1 = Math.max(a, b), min2 = Math.min(c, d), max2 = Math.max(c, d);
15+
boolean ret = (min1 < min2 && max1 < max2 && max1 > min2) || (min1 > min2 && max1 > max2 && max2 > min1);
16+
17+
System.out.println(ret ? "YES" : "NO");
18+
}
19+
}
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// AC: 233 ms
2+
// Memory: 1300 KB
3+
// .
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1974A_Phone_Desktop {
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 x = sc.nextInt(), y = sc.nextInt(), ret = 0;
14+
ret = y % 2 == 0 ? y / 2 : (y / 2 + 1);
15+
int remain = (y % 2 == 1) ? (7 * ret + 4) : 7 * ret;
16+
if (x > remain) {
17+
ret += (x - remain) % 15 == 0 ? (x - remain) / 15 : ((x - remain) / 15 + 1);
18+
}
19+
20+
System.out.println(ret);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)