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

这篇博客包含了多道编程竞赛的题目及解答,包括数学计算、字符串处理、递归搜索和数组操作等。第一题是简单的算术运算;第二题寻找立方数的和;第三题是字符组合问题;第四题涉及模运算与向量操作;第五题是数组排序与条件判断;第六题是数值求和问题;第七题是递归计数;第八题是数学计算。这些题目展示了算法和数据结构的应用。
摘要由CSDN通过智能技术生成

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

第一题

截屏2021-04-03 16.31.04 图1

截屏2021-04-06 20.26.14

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

第二题

截屏2021-04-03 16.34.39
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

第三题

截屏2021-04-03 16.39.30
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

第四题

截屏2021-04-03 16.55.40
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);  //填空
    }
}

第五题

截屏2021-04-03 16.56.25
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);
	}
}

第六题

截屏2021-04-03 20.05.41
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);
				}
			}
		}
	}
}

第七题

截屏2021-04-05 15.44.59
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);
		}
	}
}

第八题

截屏2021-04-03 20.26.04
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);
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值