2012国信蓝桥初赛试题

1、比酒量

    有一群海盗(不多于20人),在船上比拼酒量。过程如下:打开一瓶酒,所有在场的人平分喝下,有几个人倒下了。再打开一瓶酒平分,又有倒下的,再次重复...... 直到开了第4瓶酒,坐着的已经所剩无几,海盗船长也在其中。当第4瓶酒平分喝下后,大家都倒下了。
    等船长醒来,发现海盗船搁浅了。他在航海日志中写到:“......昨天,我正好喝了一瓶.......奉劝大家,开船不喝酒,喝酒别开船......”
    请你根据这些信息,推断开始有多少人,每一轮喝下来还剩多少人。
    如果有多个可能的答案,请列出所有答案,每个答案占一行。
    格式是:人数,人数,...
    例如,有一种可能是:20,5,4,2,0
    答案写在“解答.txt”中,不要写在这里!

#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<queue>
#include <stack>
using namespace std;
#pragma warning(disable : 4996)
const int MAXN = 200010;


int main()
{
	int a, b, c, d;
	for(int a = 1; a <= 20; a++)
	{
		for(int b = 1; b < a; b++)
		{
			for(int c = 1; c < b; c++)
			{
				for(int d = 1; d < c; d++)
				{
					if(b * c * d + a * b * c + a * c * d + a * b * d == a * b * c * d)
					{
						printf("%d %d %d %d 0\n", a, b, c ,d);
					}
				}
			}
		}
	}
	return 0;
}
2、第一个数字

以下的静态方法实现了:把串s中第一个出现的数字的值返回。

如果找不到数字,返回-1
例如:
s = "abc24us43"  则返回2
s = "82445adb5"  则返回8
s = "ab"   则返回-1   
public static int getFirstNum(String s)
{
if(s==null || s.length()==0) return -1;

char c = s.charAt(0);
if(c>='0' && c<='9') return _____________;  //填空

return ___________________;  //填空
}
请分析代码逻辑,并推测划线处的代码。
答案写在 “解答.txt” 文件中
注意:只写划线处应该填的内容,划线前后的内容不要抄写。

c - '0'

s.substring(1)


结果填空 (满分3分) 微生物增殖

假设有两种微生物 X 和 Y

    X出生后每隔3分钟分裂一次(数目加倍),Y出生后每隔2分钟分裂一次(数目加倍)。

    一个新出生的X,半分钟之后吃掉1个Y,并且,从此开始,每隔1分钟吃1个Y。

    现在已知有新出生的 X=10, Y=89,求60分钟后Y的数目。

    如果X=10,Y=90  呢?

    本题的要求就是写出这两种初始条件下,60分钟后Y的数目。

题目的结果令你震惊吗?这不是简单的数字游戏!真实的生物圈有着同样脆弱的性质!也许因为你消灭的那只 Y 就是最终导致 Y 种群灭绝的最后一根稻草!

#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<queue>
#include <stack>
using namespace std;
#pragma warning(disable : 4996)
const int MAXN = 200010;


int main()
{
	int x, y;
	while (cin >> x >> y)
	{
		for(int i = 1; i <= 60; i++)
		{
			y -= x;
			if(i % 3 == 0)
			{
				x *= 2;
			}
			if(i % 2 == 0)
			{
				y *= 2;
			}
			cout << "y = " << y << endl;
		}
	}
	return 0;
}

1.    结果填空 (满分4分) 古堡算式

福尔摩斯到某古堡探险,看到门上写着一个奇怪的算式:

 ABCDE * ? = EDCBA

    他对华生说:“ABCDE应该代表不同的数字,问号也代表某个数字!”

    华生:“我猜也是!”

    于是,两人沉默了好久,还是没有算出合适的结果来。

    请你利用计算机的优势,找到破解的答案。

    把 ABCDE 所代表的数字写出来。

int main()
{
	for(int a = 0; a <= 9; a++)
	{
		for(int b = 0; b <= 9; b++)
		{
			for(int c = 0; c <= 9; c++)
			{
				for(int d = 0; d <= 9; d++)
				{
					for(int e = 0; e <= 9; e++)
					{
						if(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e)
						{
							int x = a * 10000 + b * 1000 + c * 100 + d * 10 + e;
							int y = e * 10000 + d * 1000 + c * 100 + b * 10 + a;
							if(y % x == 0)
							{
								printf("%d%d%d%d%d\n",a, b, c, d, e);
							}
						}
					}
				}
			}
		}
	}

	return 0;
}

1.    结果填空 (满分8分) 奇怪的比赛

 某电视台举办了低碳生活大奖赛。题目的计分规则相当奇怪:

    每位选手需要回答10个问题(其编号为1到10),越后面越有难度。答对的,当前分数翻倍;答错了则扣掉与题号相同的分数(选手必须回答问题,不回答按错误处理)。

    每位选手都有一个起步的分数为10分。

    某获胜选手最终得分刚好是100分,如果不让你看比赛过程,你能推断出他(她)哪个题目答对了,哪个题目答错了吗?

    如果把答对的记为1,答错的记为0,则10个题目的回答情况可以用仅含有1和0的串来表示。例如:0010110011 就是可能的情况。

    你的任务是算出所有可能情况。每个答案占一行。

#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<queue>
#include <stack>
using namespace std;
#pragma warning(disable : 4996)
const int MAXN = 200010;
int color[11];
int score[11];

void dfs(int cnt)
{
	if(cnt == 11)
	{
		if(score[10] != 100)
		{
			return;
		}
		for(int i = 1; i <= 10; i++)
		{
			cout << color[i];
		}
		cout << endl;
		return;
	}

	if(cnt == 1)
	{
		color[1] = 1;
		score[1] = 10 * 2;
		dfs(cnt + 1);

		color[1] = 0;
		score[1] = 10 - 1;
		dfs(cnt + 1);
	}
	else
	{
		color[cnt] = 1;
		score[cnt] = score[cnt - 1] * 2;
		dfs(cnt + 1);

		color[cnt] = 0;
		score[cnt] = score[cnt - 1] - cnt;
		dfs(cnt + 1);
	}
}

int main()
{
	dfs(1);
	return 0;
}

1.   程序设计(满分10分)密码发生器

    在对银行账户等重要权限设置密码的时候,我们常常遇到这样的烦恼:如果为了好记用生日吧,容易被破解,不安全;如果设置不好记的密码,又担心自己也会忘记;如果写在纸上,担心纸张被别人发现或弄丢了...

    这个程序的任务就是把一串拼音字母转换为6位数字(密码)。我们可以使用任何好记的拼音串(比如名字,王喜明,就写:wangximing)作为输入,程序输出6位数字。

    变换的过程如下:

    第一步. 把字符串6个一组折叠起来,比如wangximing则变为:

    wangxi

    ming

    第二步. 把所有垂直在同一个位置的字符的ascii码值相加,得出6个数字,如上面的例子,则得出:

    228 202 220 206 120 105

    第三步. 再把每个数字“缩位”处理:就是把每个位的数字相加,得出的数字如果不是一位数字,就再缩位,直到变成一位数字为止。例如: 228 => 2+2+8=12 => 1+2=3

    上面的数字缩位后变为:344836, 这就是程序最终的输出结果!

    要求程序从标准输入接收数据,在标准输出上输出结果。

    输入格式为:第一行是一个整数n(<100),表示下边有多少输入行,接下来是n行字符串,就是等待变换的字符串。

    输出格式为:n行变换后的6位密码。

    例如,输入:

5

zhangfeng

wangximing

jiujingfazi

woaibeijingtiananmen

haohaoxuexi

    则输出:

772243

344836

297332

716652

875843

#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<queue>
#include <stack>
using namespace std;
#pragma warning(disable : 4996)
const int MAXN = 100;

int main()
{
	string text;
	vector<string>str(MAXN);
	vector<int>num;
	int sum, count_str, i, j;
	while (cin >> text)
	{
		count_str = 0;
		for(i = 0; i < text.size(); i++)
		{
			if(i % 6 == 0 && i != 0)
			{
				count_str++;
			}
			str[count_str].push_back(text[i]);
		}

		if(count_str == 0)
		{
			for(i = 0; i < str[0].size(); i++)
			{
				num.push_back(str[0][i]);
			}
		}
		else
		{
			for(i = 0; i < 6; i++)//列
			{
				sum = 0;
				for(j = 0; j < count_str; j++)//行
				{
					sum += str[j][i];
				}
				if(i <= str[count_str].size() - 1)
				{
					sum += str[count_str][i];
				}
				num.push_back(sum);
			}
		}
		for(int i = 0; i < num.size(); i++)
		{
			int x = num[i];
			sum = 0;
			while (x != 0)
			{
				sum += x % 10;
				x /= 10;
			}
			while (sum / 10 != 0)
			{
				x = sum;
				sum = 0;
				while (x != 0)
				{
					sum += x % 10;
					x /= 10;
				}
			}
			cout << sum;
		}
		cout << endl;
		num.clear();
		text.clear();
		for(i = 0; i <= count_str; i++)
		{
			str[i].clear();
		}
	}
	return 0;
}

1.   程序设计(满分25分)取球游戏

    今盒子里有n个小球,AB两人轮流从盒中取球,每个人都可以看到另一个人取了多少个,也可以看到盒中还剩下多少个,并且两人都很聪明,不会做出错误的判断。

    我们约定:

    每个人从盒子中取出的球的数目必须是:137或者8个。

    轮到某一方取球时不能弃权!

    A先取球,然后双方交替取球,直到取完。

    被迫拿到最后一个球的一方为负方(输方)

    请编程确定出在双方都不判断失误的情况下,对于特定的初始球数,A是否能赢?

    程序运行时,从标准输入获得数据,其格式如下:

    先是一个整数n(n<100),表示接下来有n个整数。然后是n个整数,每个占一行(整数<10000),表示初始球数。

    程序则输出n行,表示A的输赢情况(输为0,赢为1)。

    例如,用户输入:

10

18

    则程序应该输出:

0

1

1

0

 

偶数个(1、3、7、8)组成n个球,则A有赢球的可能。
理解错误。。。
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<queue>
#include <stack>
using namespace std;
#pragma warning(disable : 4996)
int judge[10005];

int main()
{
	int i, n, t;
	judge[0] = 1;
	judge[1] = 0;
	judge[2] = 1;
	judge[3] = 0;
	judge[4] = 1;
	judge[5] = 0;
	judge[6] = 1;
	judge[7] = 0;
	judge[8] = 1;

	for(i = 9; i <= 10000; i++)
	{
		if(!judge[i-1] || !judge[i-3] || !judge[i-7] || !judge[i-8])
		{
			judge[i] = 1;
		}
		else
		{
			judge[i] = 0;
		}
	}

	cin >> t;
	while(t--)
	{
		cin >> n;
		cout << judge[n] << endl;
	}
	return 0;
}




    
    




    

posted @ 2013-05-04 12:38  N3verL4nd  阅读(121)  评论(0编辑  收藏  举报