第十一届蓝桥杯大赛第二场省赛试题

A门牌制作

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int calc(int x){
	int ans = 0;
	while(x){
		int temp = x % 10;
		if (temp == 2)   ans ++;
		x /= 10;
	}
	return ans;
}

int main(){
	int cnt = 0;
	for (int i = 1; i <= 2020; i ++){
		cnt += calc(i);
	}
	
	cout << cnt << endl;
	
	return 0;
}

B既约分数

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int gcd(int a, int b){
	return b ? gcd(b, a % b) : a;
}

int main(){
	int cnt = 0;
	for (int i = 1; i <= 2020; i ++){
		for (int j = 1; j <= 2020; j ++){
			if (gcd(i, j) == 1)   cnt ++;
		}
	}
	
	cout << cnt << endl;
	
	return 0;
} 

C蛇形填数

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 50;

int a[N][N];

int main(){
	int idx = 1;
	bool flag = false;
	
	int cnt = 0;
	int x = 1, y = 1;
	a[x][y] = idx ++;
	cnt ++;
	int d = 1;
	while(cnt < 1000){
		if (!flag){
			y ++;
			a[x][y] = idx ++;
			cnt ++;
			flag = true;
		}
		else{
			x ++;
			a[x][y] = idx ++;
			cnt ++;
			flag = false;
		}
		
		if (flag){
			int temp = d;
			while(temp --){
				x ++;
				y --;
				a[x][y] = idx ++;
				cnt ++;
			}
		}
		else{
			int temp = d;
			while(temp --){
				x --;
				y ++;
				a[x][y] = idx ++;
				cnt ++;
			}
		}
		d ++;
	}
	
	cout << a[20][20] << endl;
	
} 

D七段码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>

using namespace std;

const int N = 20;

int h[N], e[N], ne[N], idx;
bool st[N];
set<string> ss;
set<int> ss2;
int ans;

void add(int a, int b){
	e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}

void dfs1(int u){
	st[u] = true;
	for (int i = h[u]; ~i; i = ne[i]){
		int j = e[i];
		if (!ss2.count(j))   continue;
		if (st[j])   continue;
		dfs1(j);
	}
}

bool check(string str){
	memset(st, 0, sizeof st);
	ss2.clear();
	for (int i = 0; i < str.size(); i ++){
		ss2.insert((str[i] - '0'));
	}
	int u = (str[0] - '0');
	dfs1(u);
	
	for (int i = 0; i < str.size(); i ++){
		int x = (str[i] - '0');
		if (!st[x])  return false;
	}
	
	return true;
}

void dfs(int u, string str){
	//cout << u << "----" << str << endl;
	if (u > 7){
		if (!ss.count(str) && str != ""){
			if (check(str)){
			//	cout << str << endl;
				ans ++;
			} 
			ss.insert(str);
		}
		return;
	}
	
	dfs(u + 1, str);
	str += (u + '0');
	dfs(u + 1, str);
}

int main(){
	memset(h, -1, sizeof h);
	add(1, 2), add(2, 1);
	add(6, 1), add(1, 6);
	add(2, 3), add(3, 2);
	add(7, 2), add(2, 7);
	add(3, 4), add(4, 3);
	add(7, 3), add(3, 7);
	add(5, 4), add(4, 5);
	add(5, 7), add(7, 5);
	add(6, 5), add(5, 6);
	add(6, 7), add(7, 6);
	
	dfs(1, "");
	
	cout << ans << endl;

} 

成绩分析

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 1e4 + 10;

int n;
int a[N];

int main(){
	cin >> n;
	int maxd = 0;
	int mind = 0x3f3f3f3f;
	int sum = 0;
	for (int i = 1; i <= n; i ++){
		cin >> a[i];
		sum += a[i];
		maxd = max(maxd, a[i]);
		mind = min(mind, a[i]);
	}
	
	cout << maxd << endl;
	cout << mind << endl;
	double ans =  (double)(sum) / (double)(n);
	
	printf("%.2lf\n", ans);
	
	return 0;
} 

回文日期

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

bool check1(int x){
	int temp = x;
	int ans = 0;
	while(temp){
		ans = ans * 10 + temp % 10;
		temp /= 10;
	}
	return ans == x;
}

bool check2(int x){
	string str = "";
	int temp = x;
	while(temp){
		int xx = temp % 10;
		str += (xx + '0');
		temp /= 10;
	}
	reverse(str.begin(), str.end());
	
	if (str[0] == str[2] && str[2] == str[5] && str[5] == str[7]){
		if (str[1] == str[3] && str[3] == str[4] && str[4] == str[6]){
			return true;
		}
	}   
	return false;
}

int main(){
	int x;
	cin >> x;
	for (int i = x + 1; ; i ++){
		if (check1(i)){
			cout << i << endl;
			break;
		}
	}
	
	for (int i = x + 1; ; i ++){
		if (check2(i)){
			cout << i << endl;
			break;
		}
	}
}

子串分值

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

const int N = 1e5 + 10;

int ne[N], last[N];
char str[N];

map<char, int> mp;

int main(){
	scanf("%s", str + 1);
	int len = strlen(str + 1);
	
	for (char c = 'a'; c <= 'z'; c ++){
		mp[c] = 0;
	}
	
	for (int i = 1; i <= len; i ++){
		last[i] = mp[str[i]];
		mp[str[i]] = i;
	}
	
	for (char c = 'a'; c <= 'z'; c ++){
		mp[c] = len + 1;
	}
	
	for (int i = len; i >= 1; i --){
		ne[i] = mp[str[i]];
		mp[str[i]] = i;
	}
	
	long long ans = len;
	for (int i = 1; i <= len; i ++){
		int left = (i - last[i] - 1);
		int right = (ne[i] - i - 1);
		ans += left;
		ans += right;
		ans += left * right;
	}
	
	cout << ans << endl;
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值