A:ASC
package 第12届;
import java.util.Scanner;
class A_ASC {
public static void main(String[] args) {
int a = 'L';
System.out.println(a);
}
}
B:卡片
package 第12届;
import java.util.Arrays;
import java.util.Iterator;
public class B_卡片 {
static int[] num_resolve(int num) {
String[] string = (String.valueOf(num)).split("");
int[] record = new int[string.length];
for (int i = 0; i < string.length; i++) {
record[i] = Integer.valueOf(string[i]);
}
return record;
}
static int[] cards=new int[10];
public static void main(String[] args) {
Arrays.fill(cards,2021);
int num=1;
while(true) {
int[] record = num_resolve(num);
for (int i = 0; i < record.length; i++) {
if(cards[record[i]]==0) {
System.out.println(num-1);
return;
}else {
cards[record[i]]--;
}
}
num++;
}
}
}
C:直线
package 第12届;
import java.util.HashSet;
import java.util.Iterator;
public class C_直线 {
static HashSet<String> record = new HashSet<>();
static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public static void main(String[] args) {
for (int x1 = 0; x1 < 20; x1++) {
for (int y1 = 0; y1 < 21; y1++) {
for (int x2 = 0; x2 < 20; x2++) {
for (int y2 = 0; y2 < 21; y2++) {
int ky = y2 - y1;
int kx = x2 - x1;
if(kx==0) {
record.add(" " + x1);
continue;
}
int flagK = gcd(ky, kx);
String k = ky/flagK + "/" + kx/flagK;
int by = y2*kx -x2*ky;
int bx = kx;
int flagB = gcd(by, bx);
String b = by/flagB + "/" + bx/flagB;
String line = k + "-" + b;
record.add(line);
}
}
}
}
System.out.println(record.size());
}
}
D:货物摆放
package 第12届;
public class D_货物摆放 {
public static void main(String[] args) {
long num = 2021041820210418L;
int count = 0;
for (int a = 1; a <= Math.sqrt(num); a++) {
if(num%a==0) {
long n1=num/a;
for(int b=a;b<=Math.sqrt(n1);b++) {
if(n1%b==0) {
long c = n1/b;
if(c>=b&&b>=a) {
if(c>b&&b>a) {
count+=6;
}else if (a==b&&b==c) {
count+=1;
}else {
count+=3;
}
}
}
}
}
}
System.out.println(count);
}
}
E:路径
package 第12届;
import java.util.Arrays;
public class E_最短路径 {
static private int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
static private int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
public static void main(String[] args) {
boolean[] vis = new boolean[2025];
int[] d = new int[2025];
Arrays.fill(d, Integer.MAX_VALUE);
int[][] edge = new int[2025][2025];
for (int i = 0; i < edge.length; i++) {
Arrays.fill(edge[i], Integer.MAX_VALUE);
}
for (int i = 1; i <= 2021; i++) {
edge[i][i] = 0;
for (int j = i + 1; j <= Math.min(i + 21, 2021); j++) {
edge[i][j] = edge[j][i] = lcm(i, j);
}
}
d[1] = 0;
for (int i = 1; i < 2021; i++) {
int x = 0;
for (int j = 1; j < 2021; j++) {
if (!vis[j] && d[j] < d[x]) {
x = j;
vis[j] = true;
}
}
for (int j = Math.max(1, x - 21); j <= Math.min(x + 21, 2021); j++) {
d[j] = Math.min(d[j], edge[x][j] + d[x]);
}
}
System.out.println(d[2021]);
}
}
F:时间提示
package 第12届;
import java.math.BigInteger;
import java.util.Scanner;
public class F_时间显示 {
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
long us = scanner.nextLong();
long second = us/1000;
long minute = second/60;
long hour = minute/60;
System.out.printf("%02d:%02d:%02d",hour%24,minute%60,second%60);
}
}
G:最少砝码
package 第12届;
import java.util.Scanner;
public class G_最少砝码 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int count=1;
int weight=1;
int total=1;
while(total<N) {
count+=1;
weight*=3;
total=total+weight;
}
System.out.println(count);
}
}
H:杨辉三角
package 第12届;
import java.util.Scanner;
public class H_杨辉三角 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
long n = scan.nextLong();
long[] arr = new long[44725];
arr[0] = 1;
long k = 1L;
if (n == 1) {
System.out.println(1);
return;
}
for (int i = 1; i < 44725; i++) {
for (int j = i; j >= 1; j--) {
arr[j] += arr[j - 1];
if (arr[j] == n) {
System.out.println(k + i - j + 1);
return;
}
}
k += (i + 1);
}
System.out.println(((1 + n) * n / 2) + 2);
}
}
I:双向排序