2020蓝桥杯校内模拟赛(1)

A

问题描述
  在计算机存储中,15.125GB是多少MB?
答案提交
  这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

15488

B

问题描述
  1200000有多少个约数(只计算正约数)。
答案提交
  这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

96

#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>

using namespace std;

const int N = 1200000;
int ans = 0;
int main()
{
	for (int i = 1; i * i <= N; i++)
	{
		if (N % i == 0)//能整除就是约数
		{
			printf("%d %d\n", i, N / i);
			ans += 2;
		}
	}
	cout << ans << endl;
	return 0;
}

C

问题描述
  在1至2019中,有多少个数的数位中包含数字9?
  注意,有的数中的数位中包含多个9,这个数只算一次。例如,1999这个数包含数字9,在计算只是算一个数。
答案提交
  这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

544

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>

using namespace std;
int ans = 0;
void check(int x)
{
	while (x)
	{
		int t = x % 10;
		if (t == 9)
		{
			ans++;
			return;
		}
		x = x / 10;
	}
	return;
}
int main()
{
	for (int i = 1; i <= 2019; i++)
	{
		check(i);
	}
	cout << ans << endl;
	return 0;
}

D

问题描述
  一棵包含有2019个结点的树,最多包含多少个叶结点?
答案提交
  这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

2018

E

问题描述
  一个正整数如果任何一个数位不大于右边相邻的数位,则称为一个数位递增的数,例如1135是一个数位递增的数,而1024不是一个数位递增的数。
  给定正整数 n,请问在整数 1 至 n 中有多少个数位递增的数?
输入格式
  输入的第一行包含一个整数 n。
输出格式
  输出一行包含一个整数,表示答案。
样例输入
30
样例输出
26
评测用例规模与约定
  对于 40% 的评测用例,1 <= n <= 1000。
  对于 80% 的评测用例,1 <= n <= 100000。
  对于所有评测用例,1 <= n <= 1000000。

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<string>
#include<stack>

using namespace std;

//判断当前数是否递增
int work(int x)
{
	int pre = x % 10; // 取最低位
	int p;
	while (x > 0)
	{
		p = x % 10;
		if (p <= pre)
		{
			x = x / 10;
			pre = p;
		}
		else
		{
			return 0;
		}
	}
	return true;
}

int main()
{
	long n;
	cin >> n;
	int ans = 0;

	for (int i = 1; i <= n; i++)
	{
		ans = ans + work(i);
	}
	cout << ans << endl;
	return 0;
}

F

问题描述
  小明对类似于 hello 这种单词非常感兴趣,这种单词可以正好分为四段,第一段由一个或多个辅音字母组成,第二段由一个或多个元音字母组成,第三段由一个或多个辅音字母组成,第四段由一个或多个元音字母组成。
  给定一个单词,请判断这个单词是否也是这种单词,如果是请输出yes,否则请输出no。
  元音字母包括 a, e, i, o, u,共五个,其他均为辅音字母。
输入格式
  输入一行,包含一个单词,单词中只包含小写英文字母。
输出格式
  输出答案,或者为yes,或者为no。
样例输入
lanqiao
样例输出
yes
样例输入
world
样例输出
no
评测用例规模与约定
  对于所有评测用例,单词中的字母个数不超过100。

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<string>
#include<stack>

using namespace std;

//判断字符是否为元音
bool isYy(char str)
{
	if (str == 'a' || str == 'e' || str == 'i' || str == 'o' || str == 'u')
	{
		return true;
	}
	else
	{
		return false;
	}
}

int main()
{
	string str = "";
	cin >> str;
	
	//进栈操作,从尾到首进行判断,即 元-辅-元-辅
	stack<char> s;
	for (int i = 0; i < str.length(); i++)
	{
		s.push(str[i]);
	}
	
	char x;
	x = s.top();
	bool preflag = isYy(x);//判断倒数第一个字符
	bool flag;
	int count = 1;//三条竖线分割4块

	while (!s.empty())
	{
		x = s.top();
		s.pop();
		flag = isYy(x);//第一次出栈肯定相等
		if (flag == preflag)//所以继续循环,比较将从第二个开始
		{
			continue;
		}
		else
		{
			count++;
			preflag = flag;//跟随变化
		}
		

	}
	//cout << count << endl;
	if(count == 4) cout << "yes" << endl;
	else cout << "no" << endl;
	
	return 0;
}

上述题目直接循环字符串也是可以的,栈只是当时的做法

G

问题描述
  在数列 a[1], a[2], …, a[n] 中,如果对于下标 i, j, k 满足 0<i<j<k<n+1 且 a[i]<a[j]<a[k],则称 a[i], a[j], a[k] 为一组递增三元组,a[j]为递增三元组的中心。
  给定一个数列,请问数列中有多少个元素可能是递增三元组的中心。
输入格式
  输入的第一行包含一个整数 n。
  第二行包含 n 个整数 a[1], a[2], …, a[n],相邻的整数间用空格分隔,表示给定的数列。
输出格式
  输出一行包含一个整数,表示答案。
样例输入
5
1 2 5 3 5
样例输出
2
样例说明
  a[2] 和 a[4] 可能是三元组的中心。
评测用例规模与约定
  对于 50% 的评测用例,2 <= n <= 100,0 <= 数列中的数 <= 1000。
  对于所有评测用例,2 <= n <= 1000,0 <= 数列中的数 <= 10000。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;
const int N = 10005;

int a[N] , b[N] ,s[N] , n;

int main()
{
    cin >> n;
    for(int i = 0;i < n ;i ++)
    {
        scanf("%d",&a[i]);
    }
    s[0] = a[0] ; b[n-1] = a[n-1];
    for(int i = 1;i <= n ;i ++)
    {
        s[i] = min(s[i-1],a[i]);
    }
    for(int i = n - 2;i >= 0;i --)
    {
        b[i] = max(b[i + 1],a[i]);
    }
    int ans = 0;
    for(int i = 1;i < n - 1;i ++)
    {
        if(s[i - 1] < a[i] && b[i + 1] > a[i])ans++;
    }
    cout << ans << endl;
    return 0;
}

H

问题描述
  小明想知道,满足以下条件的正整数序列的数量:
  1. 第一项为 n;
  2. 第二项不超过 n;
  3. 从第三项开始,每一项小于前两项的差的绝对值。
  请计算,对于给定的 n,有多少种满足条件的序列。
输入格式
  输入一行包含一个整数 n。
输出格式
  输出一个整数,表示答案。答案可能很大,请输出答案除以10000的余数。
样例输入
4
样例输出
7
样例说明
  以下是满足条件的序列:
  4 1
  4 1 1
  4 1 2
  4 2
  4 2 1
  4 3
  4 4
评测用例规模与约定
  对于 20% 的评测用例,1 <= n <= 5;
  对于 50% 的评测用例,1 <= n <= 10;
  对于 80% 的评测用例,1 <= n <= 100;
  对于所有评测用例,1 <= n <= 1000。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;


int dfs(int pre, int now)
{
	int t = 1;//默认有一个
	for (int i = 1; i < abs(now - pre); i++) //此处判断条件也可看成出口
	{
		t += dfs(now,i);
	}
	return t;
}

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


	return 0;
}

I

问题描述
  小明有一块空地,他将这块空地划分为 n 行 m 列的小块,每行和每列的长度都为 1。
  小明选了其中的一些小块空地,种上了草,其他小块仍然保持是空地。
  这些草长得很快,每个月,草都会向外长出一些,如果一个小块种了草,则它将向自己的上、下、左、右四小块空地扩展,这四小块空地都将变为有草的小块。
  请告诉小明,k 个月后空地上哪些地方有草。
输入格式
  输入的第一行包含两个整数 n, m。
  接下来 n 行,每行包含 m 个字母,表示初始的空地状态,字母之间没有空格。如果为小数点,表示为空地,如果字母为 g,表示种了草。
  接下来包含一个整数 k。
输出格式
  输出 n 行,每行包含 m 个字母,表示 k 个月后空地的状态。如果为小数点,表示为空地,如果字母为 g,表示长了草。
样例输入
4 5
.g…

…g…

2
样例输出
gggg.
gggg.
ggggg
.ggg.
评测用例规模与约定
  对于 30% 的评测用例,2 <= n, m <= 20。
  对于 70% 的评测用例,2 <= n, m <= 100。
  对于所有评测用例,2 <= n, m <= 1000,1 <= k <= 1000。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;

#define N 25
#define M 105

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
char maze[N][M];

int n, m;
void dfs(int k,int x, int y)
{
	if (k < 1) return;
	else
	{
		int nx = x;
		int ny = y;
		for (int i = 0; i < 4; i++)
		{
			nx = x + dx[i];
			ny = y + dy[i];
			if ( nx >= 0 && ny >= 0 && nx < n && ny < m)
			{
				maze[nx][ny] = 'g';
				dfs(k - 1, nx, ny);
			}
			nx = x - dx[i];
			ny = y - dy[i];
		}
	}
}

int x[N];
int y[N];
int main()
{

	cin >> n >> m;
	int count = 1;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> maze[i][j];
			if (maze[i][j] == 'g')
			{
				x[count] = i;
				y[count] = j;
				count++;
			}
		}
	}

#if 1
	int k;
	cin >> k;

	for (int i = 1; i < count; i++)
	{
		dfs(k,x[i],y[i]);
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cout << maze[i][j];
		}
		cout << endl;
	}
#endif

	return 0;
}

方法二:bfs

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <queue>
#include <vector>

using namespace std;
const int N = 1010;
int n, m, k;
int dir[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };
char a[N][N];

struct node {
    int x, y, mon;
};
vector<node> grass;

bool inmap(int x, int y)
{
    return x >= 1 && x <= n && y >= 1 && y <= m;
}

bool check(int mon, int x, int y)
{
    if (inmap(x, y) &&  mon < k)return 1;
    else return 0;
}

void output()
{
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            printf("%c", a[i][j]);
        }
        printf("\n");
    }
}


void bfs(node start)
{
    queue<node> q;
    q.push(start);

    while (!q.empty())
    {
        node now = q.front();

        for (int i = 0; i < 4; i++)
        {
            int nx = now.x + dir[i][0];
            int ny = now.y + dir[i][1];
            if (check(now.mon, nx, ny))
            {
                a[nx][ny] = 'g';
                q.push({ nx , ny ,now.mon + 1 });
            }
        }
        q.pop();
    }
}

void input()
{
    cin >> n >> m;
    string s;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> a[i][j];
            if (a[i][j] == 'g')
            grass.push_back({ i,j,0 });
        }
    }
    cin >> k;
}


int main()
{
    input();
    for (int i = 0; i < grass.size(); i++)
    {
        bfs(grass[i]);
    }
    output();
    return 0;
}

J

问题描述
  小明要组织一台晚会,总共准备了 n 个节目。然后晚会的时间有限,他只能最终选择其中的 m 个节目。
  这 n 个节目是按照小明设想的顺序给定的,顺序不能改变。
  小明发现,观众对于晚上的喜欢程度与前几个节目的好看程度有非常大的关系,他希望选出的第一个节目尽可能好看,在此前提下希望第二个节目尽可能好看,依次类推。
  小明给每个节目定义了一个好看值,请你帮助小明选择出 m 个节目,满足他的要求。
输入格式
  输入的第一行包含两个整数 n, m ,表示节目的数量和要选择的数量。
  第二行包含 n 个整数,依次为每个节目的好看值。
输出格式
  输出一行包含 m 个整数,为选出的节目的好看值。
样例输入
5 3
3 1 2 5 4
样例输出
3 5 4
样例说明
  选择了第1, 4, 5个节目。
评测用例规模与约定
  对于 30% 的评测用例,1 <= n <= 20;
  对于 60% 的评测用例,1 <= n <= 100;
  对于所有评测用例,1 <= n <= 100000,0 <= 节目的好看值 <= 100000。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;

#define N 100005
int x[N];
int mxx[N];//存储较大值
int main()
{
	int n, m;
	cin >> n >> m;

	for (int i = 0; i < n; i++)
	{
		cin >> x[i];
	}

	//挑选出前 m 项的较大值
	for (int i = 0; i < m; i++)
	{
		int ma = x[i];
		int k = i;
		for (int j = 0; j < n; j++)
		{
			if (x[j] > ma)
			{
				ma = x[j];
				k = j;
			}
		}
		mxx[k] = ma;
		x[k] = 0;
	}

	for (int i = 0; i < n; i++)
	{
		if (mxx[i])
		{
			cout << mxx[i] << " ";
		}
	}

	return 0;
}

方法二:容器

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

int n , m;

struct node{
    int deep;
    int id;
};

bool cmp1(node a,node b)
{
    return a.deep > b.deep;
}

bool cmp2(node a,node b)
{
    return a.id < b.id;
}

vector<node> ans;
int main()
{
    cin >> n >> m;
    
    for(int i = 0;i < n ;i ++)
    {
        node t;
        cin >> t.deep;
        t.id = i;
        ans.push_back(t);
    }
    sort(ans.begin(),ans.end(),cmp1);
    sort(ans.begin(),ans.begin() + m,cmp2);
    
    for(int i = 0;i < m ;i ++)
    {
        cout << ans[i].deep << " ";
    }
    return 0;
}
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值