蓝桥杯2015年真题练习

立方变自身
题目描述
观察下面的现象,某个数字的立方,按位累加仍然等于自身。
1^3 = 1
8^3 = 512 5+1+2=8
17^3 = 4913 4+9+1+3=17

请你计算包括1,8,17在内,符合这个性质的正整数一共有多少个?

请填写该数字,不要填写任何多余的内容或说明性的文字。

public class Main {

	public static void main(String[] args) {
		int ans = 0;
		for (int i = 1; i < 10000; i++) {
			if (check(i)) {
				// System.out.println(i);
				ans++;
			}
		}
		System.out.println(ans);
	}

	public static boolean check(int i) {
		String x = i * i * i + "";
		int sum = 0;
		for (int j = 0; j < x.length(); j++) {
			sum += x.charAt(j) - '0';
		}

		if (sum == i) {
			return true;
		}
		return false;
	}
}

三羊献瑞

观察下面的加法算式:

      祥 瑞 生 辉
  +   三 羊 献 瑞
-------------------
   三 羊 生 瑞 气

(如果有对齐问题,可以参看【图1.jpg】)

其中,相同的汉字代表相同的数字,不同的汉字代表不同的数字。

请你填写“三羊献瑞”所代表的4位数字(答案唯一),不要填写任何多余内容。

public class Main1 {

	public static void main(String[] args) {
		for (int a = 1; a < 10; a++) {
			for (int b = 0; b < 10; b++) {
				if (b == a)
					continue;
				for (int c = 0; c < 10; c++) {
					if (c == b || c == a)
						continue;
					for (int d = 0; d < 10; d++) {
						if (d == c || d == b || d == a)
							continue;
						for (int e = 1; e < 10; e++) {
							if (e == d || e == c || e == b || e == a)
								continue;
							for (int f = 0; f < 10; f++) {
								if (f == e || f == d || f == c || f == b || f == a)
									continue;
								for (int g = 0; g < 10; g++) {
									if (g == f || g == e || g == d || g == c || g == b || g == a)
										continue;
									for (int h = 0; h < 10; h++) {
										if (h == g || h == f || h == e || h == d || h == c || h == b || h == a)
											continue;
										int x1 = a * 1000 + b * 100 + c * 10 + d;
										int x2 = e * 1000 + f * 100 + g * 10 + b;
										int sum = e * 10000 + f * 1000 + c * 100 + b * 10 + h;
										if (x1 + x2 == sum) {
											System.out.println(e + " " + f + " " + g + " " + b);
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

牌型种数
题目描述:
小明被劫持到X赌城,被迫与其他3人玩牌。
一副扑克牌(去掉大小王牌,共52张),均匀发给4个人,每个人13张。
这时,小明脑子里突然冒出一个问题:
如果不考虑花色,只考虑点数,也不考虑自己得到的牌的先后顺序,自己手里能拿到的初始牌型组合一共有多少种呢?
请填写该整数,不要填写任何多余的内容或说明文字。

public class Main3 {

	public static void main(String[] args) {
		int ans = 0;
		for (int n1 = 0; n1 <= 4; n1++) {
			for (int n2 = 0; n2 <= 4; n2++) {
				for (int n3 = 0; n3 <= 4; n3++) {
					for (int n4 = 0; n4 <= 4; n4++) {
						for (int n5 = 0; n5 <= 4; n5++) {
							for (int n6 = 0; n6 <= 4; n6++) {
								for (int n7 = 0; n7 <= 4; n7++) {
									for (int n8 = 0; n8 <= 4; n8++) {
										for (int n9 = 0; n9 <= 4; n9++) {
											for (int n10 = 0; n10 <= 4; n10++) {
												for (int n11 = 0; n11 <= 4; n11++) {
													for (int n12 = 0; n12 <= 4; n12++) {
														for (int n13 = 0; n13 <= 4; n13++) {
															if (n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9 + n10 + n11
																	+ n12 + n13 == 13) {
																ans++;
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		System.out.println(ans);
	}
}

饮料换购
题目描述:
乐羊羊饮料厂正在举办一次促销优惠活动。乐羊羊C型饮料,凭3个瓶盖可以再换一瓶C型饮料,并且可以一直循环下去,但不允许赊账。

请你计算一下,如果小明不浪费瓶盖,尽量地参加活动,那么,对于他初始买入的n瓶饮料,最后他一共能得到多少瓶饮料。

输入:一个整数n,表示开始购买的饮料数量(0<n<10000)
输出:一个整数,表示实际得到的饮料数

例如:
用户输入:
100
程序应该输出:
149

用户输入:
101
程序应该输出:
151

资源约定:
峰值内存消耗(含虚拟机) < 256M
CPU消耗 < 1000ms

请严格按要求输出,不要画蛇添足地打印类似:“请您输入…” 的多余内容。

所有代码放在同一个源文件中,调试通过后,拷贝提交该源码。
注意:不要使用package语句。不要使用jdk1.7及以上版本的特性。
注意:主类的名字必须是:Main,否则按无效代码处理。

import java.util.Scanner;

public class Main4 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 0;
		int sum = n;
		while (n != 0) {
			n--;
			i++;
			if (i == 3) {
				sum += 1;
				n += 1;
				i = 0;
			}
		}
		System.out.println(sum);
	}
}

加法变乘法
题目描述:
我们都知道:1+2+3+ … + 49 = 1225
现在要求你把其中两个不相邻的加号变成乘号,使得结果为2015

比如:
1+2+3+…+1011+12+…+2728+29+…+49 = 2015
就是符合要求的答案。

请你寻找另外一个可能的答案,并把位置靠前的那个乘号左边的数字提交(对于示例,就是提交10)。

注意:需要你提交的是一个整数,不要填写任何多余的内容。


public class Main2 {

	public static void main(String[] args) {
		// 第一个乘号可以在1后面,最多到46后面
		// 第二个与第一个不相邻,最多到48后面
		for (int i = 1; i <= 46; i++) {
			for (int j = i + 2; j <= 48; j++) {
				if (i * (i + 1) - (i + (i + 1)) + j * (j + 1) - (j + (j + 1)) == 2015 - 1225) {
					System.out.println(i + " " + j);
				}
			}
		}
	}
}

熊怪吃核桃

森林里有一只熊怪,很爱吃核桃。不过它有个习惯,每次都把找到的核桃分成相等的两份,吃掉一份,留一份。如果不能等分,熊怪就会扔掉一个核桃再分。第二天再继续这个过程,直到最后剩一个核桃了,直接丢掉。

有一天,熊怪发现了1543个核桃,请问,它在吃这些核桃的过程中,一共要丢掉多少个核桃。

请填写该数字(一个整数),不要填写任何多余的内容或说明文字。

public class Main5 {

	public static void main(String[] args) {
		int n = 1543;
		int r = 0;
		while (true) {
			if (n == 0) {
				break;
			}
			if (n == 1) {
				r++;
				break;
			}
			if (n % 2 == 0) {
				n /= 2;
			} else {
				n -= 1;
				r++;
			}

		}
		System.out.println(r);
	}
}

星系炸弹

在X星系的广袤空间中漂浮着许多X星人造“炸弹”,用来作为宇宙中的路标。
每个炸弹都可以设定多少天之后爆炸。
比如:阿尔法炸弹2015年1月1日放置,定时为15天,则它在2015年1月16日爆炸。
有一个贝塔炸弹,2014年11月9日放置,定时为1000天,请你计算它爆炸的准确日期。

请填写该日期,格式为 yyyy-mm-dd 即4位年份2位月份2位日期。比如:2015-02-19
请严格按照格式书写。不能出现其它文字或符号。

import java.util.Calendar;

public class Main6 {

	public static void main(String[] args) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(2014, 10, 9);
		calendar.add(Calendar.DATE, 1000);
		System.out.println(calendar.getTime().toLocaleString());
	}
}

九数分三组

1~9的数字可以组成3个3位数,设为:A,B,C, 现在要求满足如下关系:
B = 2 * A
C = 3 * A

请你写出A的所有可能答案,数字间用空格分开,数字按升序排列。

注意:只提交A的值,严格按照格式要求输出。

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main7 {

	public static void main(String[] args) {
		int ans = 0;
		List<Integer> list = new ArrayList<Integer>();
		for (int a = 1; a < 10; a++) {
			for (int b = 1; b < 10; b++) {
				if (b == a)
					continue;
				for (int c = 1; c < 10; c++) {
					if (c == b || c == a)
						continue;
					for (int d = 1; d < 10; d++) {
						if (d == c || d == b || d == a)
							continue;
						for (int e = 1; e < 10; e++) {
							if (e == d || e == c || e == b || e == a)
								continue;
							for (int f = 1; f < 10; f++) {
								if (f == e | f == d || f == c || f == b || f == a)
									continue;
								for (int g = 1; g < 10; g++) {
									if (g == f || g == e || g == d || g == c || g == b || g == a)
										continue;
									for (int h = 1; h < 10; h++) {
										if (h == g || h == f || h == e || h == d || h == c || h == b || h == a)
											continue;
										for (int i = 1; i < 10; i++) {
											if (i == h || i == g || i == f || i == e || i == d || i == c || i == b
													|| i == a)
												continue;
											int A = a * 100 + b * 10 + c;
											int B = d * 100 + e * 10 + f;
											int C = g * 100 + h * 10 + i;

											if (B == 2 * A && C == 3 * A) {
												list.add(A);
											}
										}
									}
								}
							}
						}
					}

				}
			}
		}
		Collections.sort(list);

		for (int temp : list) {
			System.out.println(temp);
		}
	}
}

移动距离

X星球居民小区的楼房全是一样的,并且按矩阵样式排列。其楼房的编号为1,2,3…
当排满一行时,从下一行相邻的楼往反方向排号。
比如:当小区排号宽度为6时,开始情形如下:

1 2 3 4 5 6
12 11 10 9 8 7
13 14 15 …

我们的问题是:已知了两个楼号m和n,需要求出它们之间的最短移动距离(不能斜线方向移动)

输入为3个整数w m n,空格分开,都在1到10000范围内
w为排号宽度,m,n为待计算的楼号。
要求输出一个整数,表示m n 两楼间最短移动距离。

例如:
用户输入:
6 8 2
则,程序应该输出:
4

再例如:
用户输入:
4 7 20
则,程序应该输出:
5

资源约定:
峰值内存消耗(含虚拟机) < 256M
CPU消耗 < 1000ms

请严格按要求输出,不要画蛇添足地打印类似:“请您输入…” 的多余内容。

所有代码放在同一个源文件中,调试通过后,拷贝提交该源码。
注意:不要使用package语句。不要使用jdk1.7及以上版本的特性。
注意:主类的名字必须是:Main,否则按无效代码处理。

import java.util.Scanner;

public class Main8_1 {

	public static void main(String[] args) {
		int w, m, n;
		Scanner sc = new Scanner(System.in);
		w = sc.nextInt();
		m = sc.nextInt();
		n = sc.nextInt();
		// 行号满足
		int rm = m % w == 0 ? m / w : (m / w + 1);
		int rn = n % w == 0 ? n / w : (n / w + 1);

		// 列号满足
		int cm = 0;
		int cn = 0;
		// 偶数行
		if (rm % 2 == 0)
			cm = rm * w - m + 1;
		else
			cm = w - (rm * w - m);
		if (rn % 2 == 0)
			cn = rn * w - n + 1;
		else
			cn = w - (rn * w - n);

		// 求距离
		System.out.println(Math.abs(cm - cn) + Math.abs(rm - rn));

	}
}

打印大X
小明希望用星号拼凑,打印出一个大X,他要求能够控制笔画的宽度和整个字的高度。

为了便于比对空格,所有的空白位置都以句点符来代替。

要求输入两个整数m n,表示笔的宽度,X的高度。用空格分开(0<m<n, 3<n<1000, 保证n是奇数)

要求输出一个大X

例如,用户输入:

3 9

程序应该输出:

***.....***

.***...***.

..***.***..

...*****...

....***....

...*****...

..***.***..

.***...***.

***.....***

(如有对齐问题,参看【图1.jpg】)

再例如,用户输入:

4 21

程序应该输出

****................****

.****..............****.

..****............****..

...****..........****...

....****........****....

.....****......****.....

......****....****......

.......****..****.......

........********........

.........******.........

..........****..........

.........******.........

........********........

.......****..****.......

......****....****......

.....****......****.....

....****........****....

...****..........****...

..****............****..

.****..............****.

****................****

(如有对齐问题,参看【图2.jpg】)

资源约定:

峰值内存消耗(含虚拟机) < 256M

CPU消耗 < 1000ms

请严格按要求输出,不要画蛇添足地打印类似:“请您输入…” 的多余内容。

所有代码放在同一个源文件中,调试通过后,拷贝提交该源码。

注意:不要使用package语句。不要使用jdk1.7及以上版本的特性。

注意:主类的名字必须是:Main,否则按无效代码处理。

import java.util.Scanner;

public class Main9 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = sc.nextInt();
		// 宽度
		int w = m + (n / 2) * 2;
		char[][] map = new char[n][w];

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < w; j++) {
				map[i][j] = '.';
			}

		}

		for (int i = 0; i < n; i++) {
			for (int j = i; j < i + m; j++) {
				map[i][j] = '*';
			}
		}

		for (int i = 0; i < n; i++) {
			for (int j = i; j < i + m; j++) {
				map[i][w - 1 - j] = '*';
			}
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < w; j++) {
				System.out.print(map[i][j]);
			}
			System.out.println();
		}
	}
}

立方尾不变
有些数字的立方的末尾正好是该数字本身。

比如:1,4,5,6,9,24,25,…

请你计算一下,在10000以内的数字中(指该数字,并非它立方后的数值),符合这个特征的正整数一共有多少个。

请提交该整数,不要填写任何多余的内容。

public class Main10 {

	public static void main(String[] args) {
		int ans = 0;
		for (long i = 1; i <= 10000; i++) {
			String s = "" + i;
			long b = 1;
			for (int j = 0; j < s.length(); j++) {
				b *= 10;
			}
			if (i == (i * i * i) % b) {
				System.out.println(i * i * i + " " + (i * i * i) % b);
				ans++;
			}
		}
		System.out.println(ans);
	}
}

奇妙的数字
小明发现了一个奇妙的数字。它的平方和立方正好把0~9的10个数字每个用且只用了一次。

你能猜出这个数字是多少吗?

请填写该数字,不要填写任何多余的内容。

public class Main12 {

	public static void main(String[] args) {

		for (long i = 1; i <= 10000; i++) {
			long a = i * i;
			long b = i * i * i;
			if (fun(a, b)) {
				System.out.println(i);
			}
		}
	}

	public static boolean fun(long a, long b) {

		String s = "" + a + b;
		if (s.length() != 10) {
			return false;
		}
		for (int i = 0; i < 10; i++) {
			if (!s.contains(i + "")) {
				return false;
			}
		}
		return true;
	}
}

无穷分数
无穷的分数,有时会趋向于固定的数字。

请计算【图1.jpg】所示的无穷分数,要求四舍五入,精确到小数点后5位,小数位不足的补0。
在这里插入图片描述

public class Main11 {

	public static void main(String[] args) {
		System.out.printf("%.5f", fun(1));

	}

	public static double fun(int i) {
		if (i == 100)
			return 0;
		return i / (i + fun(i + 1));
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值