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\n",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("\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 <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;
}