A Three Threes (打表
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if (n == 1) System.out.println(1);
if (n == 2) System.out.println(22);
if (n == 3) System.out.println(333);
if (n == 4) System.out.println(4444);
if (n == 5) System.out.println(55555);
if (n == 6) System.out.println(666666);
if (n == 7) System.out.println(7777777);
if (n == 8) System.out.println(88888888);
if (n == 9) System.out.println(999999999);
}
}
B Pentagon (判断是否是同类型的边
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s12 = sc.next();
String t12 = sc.next();
boolean fs12 = false; // 相邻是true
boolean ft12 = false; // 相邻是true
if (s12.charAt(1) == s12.charAt(0) + 1 || s12.charAt(1) == 'E' && s12.charAt(0) == 'A' || s12.charAt(1) == 'A' && s12.charAt(0) == 'E' || s12.charAt(0) == s12.charAt(1) + 1) fs12 = true;
if (t12.charAt(1) == t12.charAt(0) + 1 || t12.charAt(1) == 'E' && t12.charAt(0) == 'A' || t12.charAt(1) == 'A' && t12.charAt(0) == 'E' || t12.charAt(0) == t12.charAt(1) + 1) ft12 = true;
if (fs12 == ft12) System.out.println("Yes");
else System.out.println("No");
}
}
C Repunit Trio (三重循环暴力枚举
import java.util.*;
class Main {
static long[] arr = new long[1000010];
static long[] base = {1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111, 11111111111L, 111111111111L};
static long[] ans = new long[1000010];
static int idx = 0;
static int idxa = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < base.length; i ++ )
for (int j = 0; j < base.length; j++)
for (int k = 0; k < base.length; k++)
arr[idx++] = base[i] + base[j] + base[k];
Arrays.sort(arr, 0, idx);
// for (int i = 0; i < 10; i ++ ) System.out.print(arr[i] + " ");
for (int i = 0; i < idx; i ++ ) {
if (i == 0) ans[idxa ++ ] = arr[i];
else if (arr[i] != arr[i - 1]) ans[idxa ++ ] = arr[i];
}
// System.out.println(idxa);
// for (int i = 0; i < 20; i ++ ) System.out.print(ans[i] + " ");
System.out.println(ans[n - 1]);
}
}
D Erase Leaves (找出节点1的n - 1个子树的最小节点和
import java.util.*;
class Main {
static int[] h, e, ne, arr;
static int idx, idxarr;
static int n;
static int ans = 0;
private static void init() {
h = new int[2 * n + 100]; e = new int[2 * n + 100]; ne = new int[2 * n + 100];
arr = new int[2 * n + 100];
Arrays.fill(h, -1);
}
private static void add(int a, int b) {
e[idx] = b; ne[idx] = h[a]; h[a] = idx ++ ;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 找ver1的其中n - 1棵树的最小总和
n = sc.nextInt();
init();
for (int i = 1; i <= n - 1; i ++ ) {
int u = sc.nextInt(), v = sc.nextInt();
add(u, v);
add(v, u);
}
int d1 = 0;
for (int i = h[1]; i != -1; i = ne[i] ) {
int j = e[i];
arr[idxarr ++ ] = dfs(j, 1);
d1 ++ ;
}
Arrays.sort(arr, 0, idxarr);
// System.out.println("debug -> d1 : " + d1);
for (int i = 0; i < d1 - 1; i ++ ) ans += arr[i];
System.out.println(ans + 1);
}
public static int dfs(int u, int fa) {
int ret = 1;
for (int i = h[u]; i != -1; i = ne[i]) {
int j = e[i];
if (j == fa) continue;
ret += dfs(j, u);
}
return ret;
}
}
标签:AtCoder,charAt,int,System,333,static,println,out
From: https://www.cnblogs.com/llihaotian666/p/17914891.html