zoukankan      html  css  js  c++  java
  • 2020 蓝桥杯(省赛)校内模拟赛

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

    以下内容仅记录自己的做题思路,并不是标准答案

    A

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

    15488
    

    B

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

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cmath>
    
    using namespace std;
    const int N = 1200000;
    bool vis[N];
    int ans = 0;
    int main()
    {
    	for(int i = 1;i * i <= N; i++)
    	{
    		if(N % i == 0)
    		{
    			printf("%d %d
    ",i , N / i);
    			if(vis[i] == 0)ans+=2;
    		}
    	}
    	cout << ans << endl;
    	return 0;	
    } 
    
    

    C

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

    #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个结点的树,最多包含多少个叶结点?
    答案提交
      这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cmath>
    
    using namespace std;
    
    int main()
    {
    	cout << 2018 << endl;
    	return 0;
    }
    

    E

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

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    
    using namespace std;
    int ans = 0 , n ;
    bool work(int x)
    {
    	int pre = x % 10;
    	while(x)
    	{
    		int t = x % 10;
    		if(pre >= t)
    		{
    		    pre = t;
    		}else return false;
    		x /= 10;
    	}
    	return true;
    }
    int main()
    {
    	cin >> n;
    	for(int i = 1;i <= n ;i ++)
    	{
    		if(work(i)) ans++;
    	}
    	cout << ans << endl;
    	return 0;
    }
    
    

    F

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

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    
    using namespace std;
    const int N = 256; 
    char yuan[] = {'a', 'e', 'i', 'o', 'u'};
    bool vis[N];
    /*
      1. 第一段至少有一个辅音字母
      2. 第二段至少元音字母
      3. 第三段至少有一个辅音字母
      4. 第四段至少有一个元音字母(第四段不能存在辅音) 
    */
    bool work(string s)
    {
    	int i = 0;
    	while(!vis[s[i] - 'a'])i++;
    	if(i == 0)return 0;
    	while(vis[s[i] - 'a']) i++; 
    	if(i == s.size())return 0;
    	while(!vis[s[i] - 'a'])i++;
    	if(i == s.size())return 0;
    	while(vis[s[i] - 'a']) i++;
    	if(i != s.size())return 0;
    	return 1;
    }
    void init()
    {
    	for(int i = 0;i < 5;i ++)
    		vis[yuan[i] - 'a'] = 1;
    }
    int main()
    {
    	init();
    	string s;
    	cin >> s;
    	bool f = work(s);
    	if(f)cout << "yes";
    	else cout << "no";
    	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 <string>
    
    using namespace std;
    const int N = 1010;
    int  n , ans = 0;
    int f[N][N]; // 记录差值
    
    int dfs(int pre , int now)
    {
    	if(f[pre][now] != -1)return f[pre][now];
    	int t = 1;
    	for(int i = 1;i < abs(pre - now) ;i++)
    	{
    		t += dfs(now , i);
    	}
    	return f[pre][now] = t % 10000;
    }
    int main()
    {
    	fill(f[0],f[0] + N * N ,-1);
    	cin >> n;
    	f[1][1] = 1;
    
    	for(int i = 1;i <= n ;i ++)
    	{
    		ans = ( ans + dfs(n, i) ) % 10000;
    	}
    	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 <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("
    ");
    	}
    }
    
    
    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 <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;
    }
    
    
  • 相关阅读:
    vue-cli的npm run build的常见问题
    es6 Symbol
    es6 对象的扩展
    es7 函数绑定
    es6 箭头函数
    学习weex遇见非常奇怪的问题
    微信
    java面试题
    PHP面试题
    Android
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12497255.html
Copyright © 2011-2022 走看看