【蓝桥杯】2014年蓝桥杯省赛A组题

A组1 猜年龄

题目描述

小明带两个妹妹参加元宵灯会。别人问她们多大了,她们调皮地说:

“我们俩的年龄之积是年龄之和的6倍”。小明又补充说:
“她们可不是双胞胎,年龄差肯定也不超过8岁啊。”
请你写出:小明的较小的妹妹的年龄。

思考

直接暴力呀

解法

#include <iostream>
using namespace std;

int main()
{
    
    
	int i, j;
	for (i = 1; i <= 50; i++) {
    
    
		for (j = 1; j <= 50; j++) {
    
    
			if ((i * j) == 6 * (i + j)) {
    
    
				if (i - j > 0 && i - j < 8) {
    
    
					cout << i << "  " << j << endl;
				}
			}
		}
	}
	return 0;
}

答案

10

A组2 切面条

题目描述

一根高筋拉面,中间切一刀,可以得到2根面条。
如果先对折1次,中间切一刀,可以得到3根面条。
如果连续对折2次,中间切一刀,可以得到5根面条。
那么,连续对折10次,中间切一刀,会得到多少面条呢?

答案是个整数,请通过浏览器提交答案。不要填写任何多余的内容

思考

大概就是规律题

1次–>2
2次–>5
3次–>9
4次–>17

可知 n = pow(2,10)+1

解法

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    
    
	cout << pow(2, 10) + 1 << endl;
	return 0;
}

答案

1025

A组3 神奇算式

题目描述

由4个不同的数字,组成的一个乘法算式,它们的乘积仍然由这4个数字组成。
比如:

210 x 6 = 1260
8 x 473 = 3784
27 x 81 = 2187

都符合要求。
如果满足乘法交换律的算式算作同一种情况,那么,包含上边已列出的3种情况,一共有多少种满足要求的算式。

请填写该数字,通过浏览器提交答案,不要填写多余内容(例如:列出所有算式)

思考

暴力

解法

/*
由4个不同的数字,组成的一个乘法算式,它们的乘积仍然由这4个数字组成。
比如:

210 x 6 = 1260
8 x 473 = 3784
27 x 81 = 2187

都符合要求。
如果满足乘法交换律的算式算作同一种情况,那么,包含上边已列出的3种情况,一共有多少种满足要求的算式。

请填写该数字,通过浏览器提交答案,不要填写多余内容(例如:列出所有算式)
*/

#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;

int ans = 0;

void i2s(int num, string& s) {
    
    
	stringstream ss;
	ss << num;
	ss >> s;
}

bool check(int num1, int num2) {
    
    
	string num1_s, num2_s;
	i2s(num1, num1_s);
	i2s(num2, num2_s);
	sort(num1_s.begin(), num1_s.end());
	sort(num2_s.begin(), num2_s.end());
	if (num1_s == num2_s) {
    
    
		return true;
	}
	else {
    
    
		return false;
	}
}

int main()
{
    
    
	int a, b, c, d, total, r1, r2;
	for (a = 1; a <= 9; a++) {
    
    
		for (b = 0; b <= 9; b++) {
    
    
			if (b == a)continue;
			for (c = 0; c <= 9; c++) {
    
    
				if (c == b || c == a)continue;
				for (d = 0; d <= 9; d++) {
    
    
					if (d == c || d == b || d == a)continue;
					total = a * 1000 + b * 100 + c * 10 + d;
					if (b != 0) {
    
    
						r1 = a * (b * 100 + c * 10 + d);
						if (check(total,r1)) {
    
    
							ans++;
							cout << a << "*" << b << c << d << endl;
						}
					}
					if (c != 0) {
    
    
						r2 = (a * 10 + b) * (c * 10 + d);
						if (check(total,r2)) {
    
    
							ans++;
							cout << a << b << "*" << c << d << endl;
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

out:

15*93
21*60
21*87
27*81
30*51
3*501
3*510
35*41
41*35
51*30
60*21
6*201
6*210
81*27
8*473
87*21
93*15
9*351
18

其中有个重复6个,18-6=12

答案

12

A组4/5代码填空

A组6 扑克序列

题目描述

A A 2 2 3 3 4 4, 一共4对扑克牌。请你把它们排成一行。
要求:两个A中间有1张牌,两个2之间有2张牌,两个3之间有3张牌,两个4之间有4张牌。

请填写出所有符合要求的排列中,字典序最小的那个。

例如:22AA3344 比 A2A23344 字典序小。当然,它们都不是满足要求的答案。

请通过浏览器提交答案。“A”一定不要用小写字母a,也不要用“1”代替。字符间一定不要留空格。

思考

全排列+check

解法

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

bool check(const string &s) {
    
    
	if ((s.rfind('A') - s.find('A') == 2) && (s.rfind('2') - s.find('2') == 3) && (s.rfind('3') - s.find('3') == 4) && (s.rfind('4') - s.find('4') == 5))
		return true;
	else 
		return false;
}

int main()
{
    
    
	string puke = "22AA3344";
	do {
    
    
		if (check(puke)) {
    
    
			cout << puke << endl;
		}
	} while (next_permutation(puke.begin(), puke.end()));
	return 0;
}

答案

2342A3A4

A组7 蚂蚁感冒

题目描述

思考

解法

答案

猜你喜欢

转载自blog.csdn.net/Fosu_Chenai/article/details/111192329