2015年第六届蓝桥杯参赛 Java B 组真题
第一题


答案: 7 ∗ ( 2 + 6 ) / 2 = 28 7 * (2 + 6) / 2 = 28 7∗(2+6)/2=28
第二题

public class Q2 {
static int ans = 0;
public static void main(String[] args) {
for (int i = 1; i < 100; i++) {
if (sum(i * i * i) == i) {
System.out.println(i + "^3 = " + (i * i * i));
ans++;
}
}
System.out.println(ans);
}
static int sum(int x) {
int sum = 0;
while (x > 0) {
sum += x % 10;
x /= 10;
}
return sum;
}
}
答案:6
第三题

public class Q3 {
// a = {三,羊,献,瑞,祥,生,辉,气}
static int[] a = new int[8];
static boolean[] book = new boolean[10];
public static void main(String[] args) {
dfs(0);
}
static void dfs(int step) {
if (step == 8) {
int x = a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3];
int y = a[4] * 1000 + a[3] * 100 + a[5] * 10 + a[6];
int z = a[0] * 10000 + a[1] * 1000 + a[5] * 100 + a[3] * 10 + a[7];
if (x + y == z) {
System.out.println(x);
}
return;
}
for (int i = 0; i < 10; i++) {
if (i == 0 && (step == 0 || step == 4))
continue;
if (!book[i]) {
book[i] = true;
a[step] = i;
dfs(step + 1);
book[i] = false;
}
}
}
}
答案:三 = 1,羊 = 0,献 = 8,瑞 = 5
第四题

public static int f(int n, int m)
{
n = n % m;
Vector v = new Vector();
for(;;)
{
v.add(n);
n *= 10;
n = n % m;
if(n==0) return 0;
if(v.indexOf(n)>=0) return v.size() - v.indexOf(n); //填空
}
}
第五题

public class Q5
{
public static void test(int[] x)
{
int a = x[0]*1000 + x[1]*100 + x[2]*10 + x[3];
int b = x[4]*10000 + x[5]*1000 + x[6]*100 + x[7]*10 + x[8];
if(a*3==b) System.out.println(a + " " + b);
}
public static void f(int[] x, int k)
{
if(k>=x.length){
test(x);
return;
}
for(int i=k; i<x.length; i++){
{int t=x[k]; x[k]=x[i]; x[i]=t;}
f(x,k+1);
{int t=x[k]; x[k]=x[i]; x[i]=t;} // 填空
}
}
public static void main(String[] args)
{
int[] x = {1,2,3,4,5,6,7,8,9};
f(x,0);
}
}
第六题

public class Q6 {
public static void main(String[] args) {
for (int i = 1; i < 47; i++) {
int sum = 1225 + i * (i + 1) - i - (i + 1);
for (int j = i + 2; j < 49; j++) {
if (sum + j * (j + 1) - j - (j + 1) == 2015) {
System.out.println(i + " " + j);
}
}
}
}
}
第七题

public class Q7 {
static long ans = 0;
public static void main(String[] args) {
dfs(0, 1);
System.out.println(ans);
}
static void dfs(int cnt, int k) {
if (cnt == 13) {
ans++;
}
if (cnt >= 13 || k > 13) {
return;
}
// 点数 k 可以拿 0、1、2、3、4 张
for (int i = 0; i <= 4; i++) {
dfs(cnt + i, k + 1);
}
}
}
第八题

import java.util.Scanner;
public class Q8 {
static int n, ans;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ans = n = sc.nextInt();
while (n >= 3) {
ans += 1;
n -= 2;
}
System.out.println(ans);
}
}