首页 › 题库 › 信息学奥赛 › 信息学奥赛-入门级

信息学奥赛-入门级 题库

共 1088 道题 ,第 43 / 55 页 · 按题型筛选,点「查看答案」核对解析
841 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int fun(int n) {
	if (n == 1)
		return 1;
	if (n == 2)
		return 2;
	return fun(n - 2) - fun(n - 1);
}

int main() {
	int n;
	cin >> n;
	cout << fun(n) << endl;
	return 0;
}

输入: 7

输出:           

答案与解析
参考答案

-11

题目详情
842 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string st;
	int i, len;
	getline(cin, st);
	len = st.size();
	for (i = 0; i < len; i++){
		if (st[i] >= 'a' && st[i] <= 'z')
			st[i] = st[i] - 'a' + 'A';
	}
	cout << st << endl;
	return 0;
}

输入: Hello, my name is Lostmonkey.

输出:                                                     

答案与解析
参考答案

HELLO, MY NAME IS LOSTMONKEY.

题目详情
843 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

const int SIZE = 100;

int main()
{
	int p[SIZE];
	int n, tot, i, cn;
	tot = 0;
	cin >> n;
	for (i = 1; i <= n; i++)
		p[i] = 1;
	for (i = 2; i <= n; i++){
		if (p[i] == 1)
			tot++;
		cn = i * 2;
		while (cn <= n) {
			p[cn] = 0;
			cn += i;
		}
	}
	cout << tot << endl;
	return 0;
}

输入: 30

输出:              

答案与解析
参考答案

10

题目详情
844 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 4.1 函数定义调用

完善程序:(数字删除)下面程序的功能是将字符串中的数字字符删除后输出。请填空。(每空3分, 共12分)


#include <iostream>

using namespace std;


int delnum(char *s) {

int i, j;

j = 0;

for (i = 0; s[i] != '\0'; i++)

if (s[i] < '0'    (1)     s[i] > '9') {

s[j] = s[i];

                      (2)    ;

}

return     (3)    ;

}


const int SIZE = 30;


int main() {

char s[SIZE];

int len, i;

cin.getline(s, sizeof(s));

len = delnum(s);

for (i = 0; i < len; i++)

cout <<     (4)    ;

cout << endl;

return 0;

}

答案与解析
参考答案

(1)||

(2)j++ 或 j=j+1 或 ++j

(3)j

(4)s[i]

题目详情
845 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 4.1 函数定义调用

完善程序:(最大子矩阵和)给出m行n列的整数矩阵,求最大的子矩阵和(子矩阵不能为空)。

输入第一行包含两个整数m和n,即矩阵的行数和列数。之后m行,每行n个整 数,描述整个矩阵。程序最终输出最大的子矩阵和。 (最后一空 4 分, 其余 3 分, 共 16 分)


#include <iostream>

using namespace std;


const int SIZE = 100;

int matrix[SIZE + 1][SIZE + 1];

int rowsum[SIZE + 1][SIZE + 1];   //rowsum[i][j]记录第 i 行前 j 个数的和 int m, n, i, j, first, last, area, ans;


int main() {

cin >> m >> n;

for (i = 1; i <= m; i++)

for (j = 1; j <= n; j++)

cin >> matrix[i][j];

ans = matrix     (1)     ;

for (i = 1; i <= m; i++)

        (2)    ;

for (i = 1; i <= m; i++)

for (j = 1; j <= n; j++)

rowsum[i][j] =     (3)     ;

for (first = 1; first <= n; first++)

for (last = first; last <= n; last++) {

                       (4)    ;

for (i = 1; i <= m; i++) {

area +=     (5)    ;

if (area > ans)

ans = area;

if (area < 0)

area = 0;

}

}

cout << ans << endl;

return 0;

}

答案与解析
参考答案

(1)[1][1]

(2)rowsum[i][0]=0

(3)rowsum[i][j-1]+matrix[i][j]

(4)area=0

(5)rowsum[i][last]-rowsum[i][first-1]

题目详情
846 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.2 运算符

7 个同学围坐一圈,要选2个不相邻的作为代表,有           种不同的选法。

答案与解析
参考答案

14

题目详情
847 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.2 运算符

某系统自称使用了一种防窃听的方式验证用户密码。密码是n个数 s1, s2, … , sn ,均为0或1。该系统每次随机生成n个数a1, a2, … , an,均为0或1,请用户回答(s1a1+s2a2+… +snan)除以2的余数。如果多次的回答总是正确,即认为掌握密码。该系统认为, 即使 问答的过程被泄露, 也无助于破解密码—— 因为用户并没有直接发送密码。

然而, 事与愿违。例如,当n= 4 时, 有人窃听了以下 5 次问答:

就破解出了密码 s1=               ,s2=               ,s3=                ,s4=                。

答案与解析
参考答案

s1 = 0,s2 = 1,s3 = 1,s4 = 1

题目详情
848 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int main()
{
	int a, b;
	cin>>a>>b;
	cout<<a<<"+"<<b<<"="<<a+b<<endl;
}


输入: 3 5

输出:                  

答案与解析
参考答案

3+5=8

题目详情
849 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int main()
{
	int a, b, u, i, num;

	cin>>a>>b>>u;
	num = 0;
	for (i = a; i <= b; i++)
		if ((i % u) == 0)
			num++;
	cout<<num<<endl;
	return 0;
}


输入: 1 100 15

输出:                   

答案与解析
参考答案

6

题目详情
850 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int main()
{
	const int SIZE = 100;

	int n, f, i, left, right, middle, a[SIZE];

	cin>>n>>f;
	for (i = 1; i <= n; i++)

		cin>>a[i];
	left = 1;
	right = n;
	do {
		middle = (left + right) / 2;
		if (f <= a[middle])
			right = middle;
		else
			left = middle + 1;
	} while (left < right);
	cout<<left<<endl;
	return 0;
}

输入:

12 17
2 4 6 9 11 15 17 18 19 20 21 25

输出:       

                                     

答案与解析
参考答案

7

题目详情
851 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int main()
{
	const int SIZE = 100;
	int height[SIZE], num[SIZE], n, ans;
	cin>>n;
	for (int i = 0; i < n; i++) {
		cin>>height[i];
		num[i] = 1;
		for (int j = 0; j < i; j++) {
			if ((height[j] < height[i]) && (num[j] >= num[i]))
				num[i] = num[j]+1;
		}
	}
	ans = 0;
	for (int i = 0; i < n; i++) {

		if (num[i] > ans) ans = num[i];
	}
	cout<<ans<<endl;
}

输入:

6

2 5 3 11 12 4

输出:   

                            

答案与解析
参考答案

4

题目详情
852 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 4.1 函数定义调用

完善程序:(序列重排)全局数组变量a定义如下:

const int SIZE = 100;

int a[SIZE], n;

它记录着一个长度为n的序列a[1],a[2], … , a[n]。

现在需要一个函数,以整数p(1≤p≤n)为参数,实现如下功能:将序列a的前p个数与后n–p个数对调,且不改变这p 个数(或n–p个数)之间的相对位置。例如,长度为5的序列1,2,3,4,5,当p=2 时重排结果为3,4,5,1,2。

有一种朴素的算法可以实现这一需求,其时间复杂度为O(n)、空间复杂度为O(n):


void swap1(int p)

{

int i, j, b[SIZE];


for (i = 1; i <= p; i++)

b[    (1)    ] = a[i];                           //(3 分)

for (i = p + 1; i <= n; i++)

b[i - p] =    (2)     ;                          //(3 分)

for (i = 1; i <=     (3)     ; i++)                //(2 分)

a[i] = b[i];

}


我们也可以用时间换空间,使用时间复杂度为O(n2)、空间复杂度为O(1)的算法:


void swap2(int p)

{


int i, j, temp;


for (i = p + 1; i <= n; i++) {

temp = a[i];

for (j = i; j >=     (4)     ; j--)                   //(3 分)

a[j] = a[j - 1];

     (5)    = temp;                                                    //(3 分)

}

}

答案与解析
参考答案

(1)n – p + i

(2)a[i]

(3)n

(4)i – p + 1

(5)a[i – p]

题目详情
853 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 4.1 函数定义调用

完善程序:(二叉查找树)二叉查找树具有如下性质:每个节点的值都大于其左子树上所有节点的 值、小于其右子树上所有节点的值。 试判断一棵树是否为二叉查找树。

输入的第一行包含一个整数n,表示这棵树有n个顶点, 编号分别为1,2, … ,n,其 中编号为1的为根结点。之后的第i行有三个数value,left_child,right_child,分别表示 该节点关键字的值、左子节点的编号、右子节点的编号;如果不存在左子节点或右子节 点,则用0代替。输出1表示这棵树是二叉查找树,输出0则表示不是。


#include <iostream>

using namespace std;


const int SIZE = 100;

const int INFINITE = 1000000;


struct node {

int left_child, right_child, value;

};


node a[SIZE];


int is_bst(int root, int lower_bound, int upper_bound)

{

int cur;


if (root == 0)

return 1;

cur = a[root].value;

if ((cur > lower_bound) && (     (1)     ) &&             //(3 分)


(is_bst(a[root].left_child, lower_bound, cur) == 1) && 

(is_bst(    (2)     ,    (3)     ,     (4)     ) == 1))    //(3 分,3 分,3 分)

return 1;

return 0;

}


int main()

{

int i, n;

cin>>n;

for (i = 1; i <= n; i++)

cin>>a[i].value>>a[i].left_child>>a[i].right_child;

cout<<is_bst(    (5)    , -INFINITE, INFINITE)<<endl;    //(2 分) 

return 0;

}

答案与解析
参考答案

(1)cur < upper_bound

(2)a[root].right_child

(3)cur

(4)upper_bound

(5)1

题目详情
854 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.2 运算符

如果平面上任取n个整点(横纵坐标都是整数) ,其中一定存在两个点,它们连线的中点也是整点,那么n至少是            。

答案与解析
参考答案

5

题目详情
855 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.2 运算符

在NOI期间,主办单位为了欢迎来自全国各地的选手,举行了盛大的晚宴。在第十八桌,有5名大陆选手和5名港澳选手共同进膳。为了增进交流,他们决定相隔就坐,即每个大陆选手左右相邻的都是港澳选手、每个港澳选手左右相邻的都是大陆选手。那么,这一桌共有            种不同的就坐方案。注意:如果在两个方案中,每个选手左边相邻的选手均相同,则视为同一个方案。

答案与解析
参考答案

2880

题目详情
856 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>
using namespace std;

int a, b, c, d, e, ans;

int main()
{
	cin>>a>>b>>c;
	d = a+b;
	e = b+c;
	ans = d+e;
	cout<<ans<<endl;
}


输入: 1 2 5

输出:           

答案与解析
参考答案

10

题目详情
857 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include<iostream>
using namespace std;

int n, i, ans;

int main()
{
	cin>>n;
	ans = 0;
	for (i = 1; i <= n; i++)
		if (n % i == 0)
			ans++;
	cout<<ans<<endl;
}


输入: 18

输出:            

答案与解析
参考答案

6

题目详情
858 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>

using namespace std;
int n, i,j, a[100][100];

int solve(int x, inty)
{
	int u, v;

	if (x == n)
		return a[x][y];
	u = solve(x + 1, y);
	v = solve(x + 1, y + 1);
	if (u > v)
		return a[x][y] + u;
	else
		return a[x][y] + v;
}

int main()
{
	cin>>n;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= i; j++)
			cin>>a[i][j];
	cout<<solve(1, 1)<<endl;
	return 0;
}


输入 :

5

2

-1 4

2 -1 -2

-1 6 4 0

3 2 -1 5 8

输出:                     

答案与解析
参考答案

14

题目详情
859 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 2.1 数据类型
#include <iostream>

#include <string>
using namespace std;

int n, ans, i, j;
string s;

charget(inti)
{
	if (i < n)
		return s[i];
	else
		return s[i-n];
}
int main()
{
	cin>>s;
	n = s.size();
	ans = 0;
	for (i = 1; i <= n-1; i++)
	{
		for (j = 0; j <= n-1; j++) if (get(i+j) < get(ans+j))
		{
			ans = i;
			break;
		}
		else if (get(i+j) > get(ans+j))
			break;
	}
	for (j = 0; j <= n-1; j++)
		cout<<get(ans+j);
	cout<<endl;
}


输入: CBBADADA

输出:                   

答案与解析
参考答案

ACBBADAD

题目详情
860 简答题 偏难 信息学奥赛 ·信息学奥赛-入门级 · 4.1 函数定义调用

完善程序:坐标统计

输入 n 个整点在平面上的坐标。 对于每个点,可以控制所有位于它左下方的点(即 x 、y 坐标都比它小),它可以控制的点的数目称为“战斗力”。依次输出每个点的战斗力,最后输出战斗力最高的点的编号(如果两个点战斗力一样,    输出较大的编号)。


#include<iostream>

using namespace std;


const int SIZE = 100;


intx[SIZE], y[SIZE], f[SIZE];

int n, i,j, max_f, ans;


int main()

{

cin>>n;

for (i = 1; i <= n; i++)

cin>>x[i]>>y[i];

max_f = 0;

for (i = 1; i <= n; i++)

{

f[i] =          ①      ;

for (j = 1; j <= n; j++)


{

if (x[j] < x[i] &&           ②    )

③    

}

if (        ④     )

{

max_f = f[i];

      ⑤      ;

}

}

for (i = 1; i <= n; i++)

cout<<f[i]<<endl;

cout<<ans<<endl;

}

答案与解析
参考答案

①0

②y[j] < y[i](或 y[i] > y[j])

③f[i]++(或++f[i],或 f[i] = f[i] + 1)

④f[i] >= max_f(或 max_f <= f[i],两种答案均必须有等号)

⑤ans = i

题目详情