第十一屆 藍橋杯校內模擬賽

一、

  • 1200000有多少個約數(只計算正約數)。
    答案:96

二、

  • 在計算機存儲中,15.125GB是多少MB?
    答案:15488

三、

  • 在1至2019中,有多少個數的數位中包含數字9?
     答案:544

四、

  • 一棵包含有2019個結點的樹,最多包含多少個葉結點?
    答案:2018

五、

  • 一個正整數如果任何一個數位不大於右邊相鄰的數位,則稱爲一個數位遞增的數,例如1135是一個數位遞增的數,而1024不是一個數位遞增的數。給定正整數 n,請問在整數 1 至 n 中有多少個數位遞增的數?
  • O(n)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; 
int n, ans;
bool ok(int x) {
	int t = 10;
	while (x) {
		int d = x % 10;
		if (d > t) return false;
		t = d;
		x /= 10;
	}
	return true;
}
int main() {
 	scanf("%d", &n);
 	for (int i = 1; i <= n; i++) {
 		if (ok(i)) ans++;
	 }
 	printf("%d", ans);
	return 0;
} 

  • 在數列 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]爲遞增三元組的中心。給定一個數列,請問數列中有多少個元素可能是遞增三元組的中心。
  • O(n2)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; 
const int N = 1005;
int n, p[N], ans;
bool ok(int x) {
	bool ok = false;
	for (int i = x - 1; i >= 1; i--) {
		if (p[i] < p[x]) {
			ok = true; break;
		}
	}
	if (!ok) return false;
	for (int i = x + 1; i <= n; i++) {
		if (p[x] < p[i]) return true;
	}
	return false;	
}
int main() {
 	scanf("%d", &n);
 	for (int i = 1; i <= n; i++) {
		scanf("%d", &p[i]); 
	}
	for (int i = 1; i <= n; i++) {
		if (ok(i)) ans++;
	}
 	printf("%d", ans);
	return 0;
} 

七、

  • 小明對類似於 hello 這種單詞非常感興趣,這種單詞可以正好分爲四段,第一段由一個或多個輔音字母組成,第二段由一個或多個元音字母組成,第三段由一個或多個輔音字母組成,第四段由一個或多個元音字母組成。給定一個單詞,請判斷這個單詞是否也是這種單詞,如果是請輸出yes,否則請輸出no。元音字母包括 a, e, i, o, u,共五個,其他均爲輔音字母。
  • O(n)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; 
const int N = 105;
int n;
char s[N], h[5] = {'a', 'e', 'i', 'o', 'u'};
bool ok(int x) {
	for (int i = 0; i < 5; i++) {
		if (h[i] == s[x]) return true;
	}
	return false;
}
bool solve() {
	n = strlen(s + 1);
	//找第一段
	int t = 1;
	for (; t <= n; t++) {
		if (ok(t)) {break;}
	} 
	//找第二段
	if (t >= n || t == 1) return false;
	for (; t <= n; t++) {
		if (!ok(t)) {break;}
	} 
	//找第三段
	if (t >= n) return false;
	for (; t <= n; t++) {
		if (ok(t)) {break;}
	} 
	//找第四段
	if (t > n) return false;
	for (; t <= n; t++) {
		if (!ok(t)) {break;}
	} 
	if (t == n + 1) return true;
	return false;	
}
int main() {
  	scanf("%s", s + 1);
	if (solve()) printf("yes");
	else printf("no");
	return 0;
} 

八、

九、

十、

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章