Skip to content

Commit fb09c91

Browse files
committed
update
1 parent 73b5023 commit fb09c91

7 files changed

+150
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// AC: 404 ms
2+
// Memory: 0 KB
3+
// .
4+
// T:O(logn), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_0102B_Sum_of_Digits {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
String n = sc.next();
12+
int sumDigit = 0, ret = n.length() > 1 ? 1 : 0;
13+
for (char c : n.toCharArray()) {
14+
sumDigit += c - '0';
15+
}
16+
while (sumDigit >= 10) {
17+
int copy = sumDigit, tempSum = 0;
18+
while (copy > 0) {
19+
tempSum += copy % 10;
20+
copy /= 10;
21+
}
22+
sumDigit = tempSum;
23+
ret++;
24+
}
25+
System.out.println(ret);
26+
}
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// AC: 218 ms
2+
// Memory: 0 KB
3+
// .
4+
// T:O(1), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_0448A_Rewards {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int a1 = sc.nextInt(), a2 = sc.nextInt(), a3 = sc.nextInt(), b1 = sc.nextInt(), b2 = sc.nextInt(),
12+
b3 = sc.nextInt(), x = sc.nextInt();
13+
int sum1 = a1 + a2 + a3, sum2 = b1 + b2 + b3,
14+
needed = (sum1 % 5 == 0 ? sum1 / 5 : (sum1 / 5 + 1)) + (sum2 % 10 == 0 ? sum2 / 10 : (sum2 / 10 + 1));
15+
System.out.println(needed <= x ? "YES" : "NO");
16+
}
17+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// AC: 280 ms
2+
// Memory: 0 KB
3+
// Math.
4+
// T:O(sum(log ni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_0598A_Tricky_Sum {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt(), maxScore = 0;
12+
for (int i = 0; i < t; i++) {
13+
int n = sc.nextInt();
14+
long sum = (long) n * (n + 1) / 2, ret = 0;
15+
int largestPower = findLargestPowerBelow(n);
16+
ret = sum - 2 * (2L * largestPower - 1);
17+
18+
System.out.println(ret);
19+
}
20+
}
21+
22+
private static int findLargestPowerBelow(int num) {
23+
int cur = 1, base = 2;
24+
for (int exp = 0; exp < 31; exp++) {
25+
if (num >= cur && num < cur * base) {
26+
return cur;
27+
}
28+
cur *= base;
29+
}
30+
31+
return -1;
32+
}
33+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// AC: 233 ms
2+
// Memory: 0 KB
3+
// .
4+
// T:O(n), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1041A_Heist {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int n = sc.nextInt(), minVal = Integer.MAX_VALUE, maxVal = 0;
12+
for (int i = 0; i < n; i++) {
13+
int a = sc.nextInt();
14+
minVal = Math.min(minVal, a);
15+
maxVal = Math.max(maxVal, a);
16+
}
17+
System.out.println(maxVal - minVal + 1 - n);
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// AC: 217 ms
2+
// Memory: 0 KB
3+
// Math: 等差数列.
4+
// T:O(1), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1180A_Alex_and_a_Rhombus {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int n = sc.nextInt();
12+
System.out.println(1 + 4 * n * (n - 1) / 2);
13+
}
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// AC: Runtime 38 ms Beats 5.92% of users with Java
2+
// Memory 56.12 MB Beats 82.70% of users with Java
3+
// Sort.
4+
// T:O(nlogn), S:O(logn)
5+
//
6+
class Solution {
7+
public long largestPerimeter(int[] nums) {
8+
Arrays.sort(nums);
9+
int len = nums.length;
10+
long curSum = 0;
11+
for (int num : nums) {
12+
curSum += num;
13+
}
14+
for (int i = len - 1; i >= 2; i--) {
15+
if (nums[i] < curSum - nums[i]) {
16+
return curSum;
17+
}
18+
curSum -= nums[i];
19+
}
20+
21+
return -1;
22+
}
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// AC: Runtime 2 ms Beats 33.33% of users with Java
2+
// Memory 43.77 MB Beats 33.33% of users with Java
3+
// Find the two or more even numbers.
4+
// T:O(n), S:O(1)
5+
//
6+
class Solution {
7+
public boolean hasTrailingZeros(int[] nums) {
8+
int countEven = 0;
9+
for (int num : nums) {
10+
if (num % 2 == 0) {
11+
countEven++;
12+
}
13+
}
14+
15+
return countEven >= 2;
16+
}
17+
}

0 commit comments

Comments
 (0)