附:友情链接之 Tsinsen 第一卷 题解 1000-1024(已完结)
1053 The Next Cow
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long n = sc.nextInt();
System.out.println(n+1);
}
}
1054 奶牛的罢工
import java.util.*;
public class Main {
static boolean prime(int x) {
if (x == 1)
return false;
for (int i = 2; i <= Math.sqrt(x); i++)
if (x % i == 0) {
return false;
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
do {
n = n + 2;
} while (prime(n) == false);
System.out.println(n);
}
}
1055 “The Next Cow” Strikes Back
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String a = sc.next();
String b = null;
String c = null;
int flag = 0;
for (int i = 1; i <= n; i++) {
b = sc.next();
if (flag == 0) {
if (a.compareTo(b) < 0) {
c = b;
flag = 1;
}
} else if (flag == 1) {
if (b.compareTo(c) < 0 && b.compareTo(a) > 0) {
c = b;
System.out.println(c);
}
}
}
if (flag == 1) {
System.out.println(c);
} else if (flag == 0) {
System.out.println("The End");
}
}
}
1058 芯片测试
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] a = new int[20][20];
int[] b = new int[20];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
a[i][j] = sc.nextInt();
if (a[i][j] > 0) {
b[j]++;
}
}
}
sc.close();
for (int i = 1; i <= n; i++) {
if (b[i] >= (n + 1) / 2) {
System.out.print(i);
if (i != n) {
System.out.print(" ");
}
}
}
}
}
1059 求解二元整数不定方程
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String []s = str.split(",");
int a = Integer.parseInt(s[0]);
int b = Integer.parseInt(s[1]);
int m = Integer.parseInt(s[2]);
for (int x=1;x<m;x++){
for (int y=1;a*x+b*y<=m;y++){
if(y>=x){
System.out.println(x+","+y);
}
}
}
}
}
Tsinsen 的题解系列涵盖1053到1059题目,包括"The Next Cow"的后续,奶牛罢工问题,字符串解析与芯片测试挑战,以及解决二元整数不定方程的策略。每个题目都附有详细解析,是编程解题爱好者的参考资料。
125

被折叠的 条评论
为什么被折叠?



