Skip to content

Commit 56e1da6

Browse files
committed
update
1 parent 887b534 commit 56e1da6

7 files changed

+205
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Time: 265 ms
2+
// Memory: 1100 KB
3+
// .
4+
// T:O(sum(k)), S:O(max(k))
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1772C_Different_Differences {
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 k = sc.nextInt(), n = sc.nextInt(), cur = 1, curDiff = 1;
14+
StringBuilder ret = new StringBuilder();
15+
while (cur <= n) {
16+
ret.append(cur);
17+
if (cur >= n) {
18+
break;
19+
}
20+
k--;
21+
if (n - cur == k) {
22+
cur++;
23+
} else {
24+
if (n - cur - curDiff < k - 1) {
25+
cur++;
26+
} else {
27+
if (cur + curDiff <= n) {
28+
cur += curDiff;
29+
} else {
30+
cur = n;
31+
}
32+
curDiff++;
33+
}
34+
}
35+
if (k == 0) {
36+
break;
37+
}
38+
ret.append(" ");
39+
}
40+
41+
System.out.println(ret);
42+
}
43+
}
44+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Time: 453 ms
2+
// Memory: 2000 KB
3+
// .
4+
// T:O(n), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1866A_Ambitious_Kid {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int n = sc.nextInt(), minVal = Integer.MAX_VALUE;
12+
for (int i = 0; i < n; i++) {
13+
int a = sc.nextInt();
14+
minVal = Math.min(minVal, Math.abs(a));
15+
}
16+
System.out.println(minVal);
17+
}
18+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Time: 749 ms
2+
// Memory: 800 KB
3+
// Constructive: 构造对称.
4+
// T:O(sum(ni)), S:O(max(ni))
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2001B_Generate_Permutation {
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+
if (n % 2 == 0) {
15+
System.out.println(-1);
16+
} else {
17+
int[] ret = new int[n];
18+
ret[n / 2] = 1;
19+
int direction = 1, pos = 1;
20+
for (int j = 1; j <= n / 2; j++) {
21+
if (direction == 1) {
22+
ret[n / 2 + j] = pos + 1;
23+
ret[n / 2 - j] = pos + 2;
24+
pos += 2;
25+
direction = -1;
26+
} else {
27+
ret[n / 2 - j] = pos + 1;
28+
ret[n / 2 + j] = pos + 2;
29+
pos += 2;
30+
direction = 1;
31+
}
32+
}
33+
for (int j = 0; j < n; j++) {
34+
System.out.print(ret[j]);
35+
if (j != n - 1) {
36+
System.out.print(" ");
37+
}
38+
}
39+
System.out.println();
40+
}
41+
}
42+
}
43+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// AC: 280 ms
2+
// Memory: 600 KB
3+
// .
4+
// T:O(sum(ni)), S:O(max(ni))
5+
//
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.Scanner;
9+
10+
public class Codeforces_2009B_osu_mania {
11+
public static void main(String[] args) {
12+
Scanner sc = new Scanner(System.in);
13+
int t = sc.nextInt();
14+
15+
for (int i = 0; i < t; i++) {
16+
int n = sc.nextInt();
17+
List<Integer> ret = new ArrayList<>();
18+
for (int j = 0; j < n; j++) {
19+
String row = sc.next();
20+
ret.add(row.indexOf('#') + 1);
21+
}
22+
StringBuilder retStr = new StringBuilder();
23+
for (int j = ret.size() - 1; j >= 0; j--) {
24+
retStr.append(ret.get(j));
25+
if (j != 0) {
26+
retStr.append(" ");
27+
}
28+
}
29+
30+
System.out.println(retStr);
31+
}
32+
}
33+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// AC: 374 ms
2+
// Memory: 1100 KB
3+
// .
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2009C_The_Legend_of_Freya_the_Frog {
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(), k = sc.nextInt(), ret = 0;
14+
int x1 = 2 * (int) Math.ceil(x * 1.0 / k) - 1, y1 = 2 * (int) Math.ceil(y * 1.0 / k);
15+
16+
System.out.println(Math.max(x1, y1));
17+
}
18+
}
19+
}
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 45.19 MB Beats 100.00%
3+
// .
4+
// T:O(n), S:O(1)
5+
//
6+
class Solution {
7+
public int countSubarrays(int[] nums) {
8+
int len = nums.length, ret = 0;
9+
for (int i = 0; i < len - 2; i++) {
10+
if ((nums[i] + nums[i + 2]) * 2 == nums[i + 1]) {
11+
ret++;
12+
}
13+
}
14+
15+
return ret;
16+
}
17+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Runtime 2 ms Beats 100.00%
2+
// Memory 44.61 MB Beats 100.00%
3+
// .
4+
// T:O(n), S:O(n)
5+
//
6+
class Solution {
7+
public int minimumOperations(int[] nums) {
8+
int len = nums.length, dupIndex = -1;
9+
if (len < 3) {
10+
if (len == 1) {
11+
return 0;
12+
} else if (len == 2) {
13+
return nums[0] == nums[1] ? 1 : 0;
14+
}
15+
} else {
16+
HashSet<Integer> record = new HashSet<>();
17+
for (int i = len - 1; i >= 0; i--) {
18+
if (record.contains(nums[i])) {
19+
dupIndex = i;
20+
break;
21+
}
22+
record.add(nums[i]);
23+
}
24+
}
25+
26+
if (dupIndex == -1) {
27+
return 0;
28+
}
29+
return (dupIndex + 1) % 3 == 0 ? (dupIndex + 1) / 3 : ((dupIndex + 1) / 3 + 1);
30+
}
31+
}

0 commit comments

Comments
 (0)