第八届省赛 c++ B组 填空题
第一题很简单,不再赘述
import java.util.*;
public class Main {
//判断是否是质数
static boolean is_prime(int x)
{
if (x < 2) return false;
for (int i = 2; i <= x / i; i ++ )
if (x % i == 0)
return false;
return true;
}
public static void main(String[] args) {
for (int i = 2; i <= 10000; i++) {
if(is_prime(i)){
for(int d = 1; d <= 10000; d++){
int k = i;
int count = 0;
while(is_prime(k)){
k+=d;
count++;
}
if(count == 10){
System.out.println(d);
return;
}
}
}
}
}
}
第八届省赛 c++ C组 填空题
第一题可以直接数出答案
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
int count = 0;
File a = new File("data/C.txt");
File a2 = new File("data/A.txt");
File a3 = new File("data/B.txt");
List list = new ArrayList<String>();
List list2 = new ArrayList<String>();
try {
InputStreamReader b = new InputStreamReader(new FileInputStream(a));
BufferedReader br = new BufferedReader(b);
String str = br.readLine();
while (str != null) {
String[] q = str.split(", ");
for (String h : q) {
list.add(h);
}
str = br.readLine();
}
//------------------------------------
InputStreamReader b2 = new InputStreamReader(new FileInputStream(a2));
BufferedReader br2 = new BufferedReader(b2);
String str2 = br2.readLine();
while (str2 != null) {
String[] q = str2.split(", ");
for (String h : q) {
list2.add(h);
}
str2 = br2.readLine();
}
//---------------------------------------
InputStreamReader b3 = new InputStreamReader(new FileInputStream(a3));
BufferedReader br3 = new BufferedReader(b3);
String str3 = br3.readLine();
while (str3 != null) {
String[] q = str3.split(", ");
for (String h : q) {
if (list2.contains(h) && !list.contains(h))
count++;
list2.add(h);
}
str3 = br3.readLine();
}
System.out.println(count);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
第八届省赛 java B组 填空题
与第八届省赛 c++ B组 填空题的第一题相同
public class Main {
static int[] a = new int[9];
static boolean[] st = new boolean[10];
static int res = 0;
static void dfs(int u) {
if (u == 9) {
int k1 = a[0] + a[1] + a[2] + a[3];
int k2 = a[0] + a[8] + a[7] + a[6];
int k3 = a[3] + a[4] + a[5] + a[6];
if (k1 == k2 && k2 == k3) {
res++;
}
return;
}
for (int i = 1; i <= 9; i++) {
if (!st[i]) {
a[u] = i;
st[i] = true;
dfs(u + 1);
st[i] = false;
}
}
}
public static void main(String[] args) {
dfs(0);
System.out.println(res / 6);
}
}