第一题:纸张尺寸
import java.io.*;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException {
String s = br.readLine();
int n = Integer.parseInt(String.valueOf(s.charAt(1)));
int p1 = 1189, p2 = 841;
for(int i = 0; i < n; i++){
int tmp = p1 / 2;
p1 = p2;
p2 = tmp;
}
out.println(p1);
out.println(p2);
out.flush();
}
}
第二题:最大数字
import java.util.Scanner;
public class Main {
static String str;
static int a, b, len;
static long res;
static void dfs(int pos, long v) {
if(pos == len) {
res = Math.max(res, v);
return;
}
int c = str.charAt(pos) - '0';
int t = Math.min(a, 9-c);
a -= t;
dfs(pos+1, v*10+c+t);
a += t;
if(b > c) {
b -= c+1;
dfs(pos+1, v*10+9);
b += c+1;
}
}
public static void main(String[] args) throws Exception {
Scanner s = new Scanner(System.in);
str = s.next();
a = s.nextInt();
b = s.nextInt();
len = str.length();
dfs(0, 0);
System.out.println(res);
}
}
第三题:全排列的价值
第四题:修路
补题中。。。。。