2020蓝桥杯十一届七月省赛CB组

2020蓝桥杯十一届七月省赛CB组

考生须知

A:跑步训练

// 模拟
#include <stdio.h>
#include <iostream>
#include <map>
using namespace std;
int main() {
	
	int start = 1000;
	int flag = 1;// 1表示要跑
	int cnt = 0;
	while (start != 0) {
		if (flag) {
			if (start - 600 >= 0) {
				start -= 600;
				cnt += 60;
			}
			else {
				cnt += (start / 10);
				start = 0;
			}
			flag = !flag;
		}
		else {
			start += 300;
			cnt += 60;
			flag = !flag;
		}
		
	}

	cout << cnt;

	return 0;
}

B:纪念日

// 使用计算器的日期计算, 题目中贴心的把时间点放在了中午十二点,如:2020/7/1 - 2020/7/2就是整整一天时间
// 36138天 分钟数 = 36138 * 24 * 60 = 52,038,720分钟

C:合并检测

// 计算数学期望然后根据k来求人数

D:REPEAT程序

// 感觉直接用记事本替换成C/C++源程序的格式会简单一点 可惜不行 没法判定有右括号位置只能用栈去做

E:矩阵

// 动态规划

F:整除序列

// 签到题目

G:解码

// 字符串的处理也挺简单的
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#define max 35
using namespace std;


int main() {
	int cnt = 0;
	string str;
	string ans = "";
	cin >> str;
	cnt = str.length();
	for (int i = 0; i < cnt; i++) {
		if ((str[i] <= 'z' && str[i] >= 'a')|| (str[i] <= 'Z' && str[i] >= 'A')) {
			ans += str[i];
		}
		else {
			int k = str[i] - '0' - 1;
			char c = str[i - 1];
			while (k--) {
				ans += c;
			}
		}
	}
	cout << ans <<endl;
	return 0;
}

H:走方格


// 动态规划
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MAXN = 40;
int dp[MAXN][MAXN];
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (i == 1 && j == 1) {
                dp[i][j] = 1;
                continue;
            }
            if ((i & 1) || (j & 1)) {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            }
        }
    }
    printf("%d\n", dp[n][m]);
    return 0;
}

I:整数拼接

// 这个先排序会好一点 我这里考虑了位数 暴力+剪枝
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#define max 35
using namespace std;
int maze[max][max];

int digits(int k) {
	int cnt = 0;
	while (k != 0) {
		cnt++;
		k /= 10;
	}
	return cnt;
}

int cal(int x, int y,int z) {
	while (y--) {
		x *= 10;
	}
	x += z;
	return x;
}

int main() {
	int n, k;
	
	cin >> n >> k;
	int cnt = (digits(k) + 1) / 2 ;
	vector<int> v;
	int temp,ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		v.push_back(temp);
	}
	sort(v.begin(), v.end());
	int len = v.size();

	for (int i = 0; i < len; i++) {
		for (int j = 0; j < len; j++) {
			if (i == j) continue;
			if ((cal(v[i], digits(v[j]),v[j]) > k)||(digits(v[i]) > cnt && digits(v[j]) > cnt) ){
				if ( j < i)
					cout << i * (len - 1) + j << endl ;
				else {
					cout << i * (len - 1) + j - 1 << endl;
				}
				return 0;
			}
			
		}
	}
	cout << len * (len - 1) << endl;
	return 0;
}

J:网络分析

J:网络分析

// 图论的知识
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#define max 10010
using namespace std;
int mat[max][max];
int ans[max];
int visit[max];
int n, m;
queue<int> que;
void bfs(int score) {
	int cur_index = 0;
	while (!que.empty()) {
		cur_index = que.front();
		que.pop();
		ans[cur_index] += score;
		cout << cur_index << "*" << ans[cur_index] << endl;
		for (int i = 1; i <= n; i++) {
			if (mat[cur_index][i] == -1 || i == cur_index) continue;
			if (visit[i] != 1) {
				que.push(i);
				visit[i] = 1;
			}
		}
	}
	fill(visit, visit + max, 0);
}

int main() {
	
	cin >> n >> m;
	int type;
	int a,b,p,t;
	
	
	for (int i = 0; i < max; i++) {
		fill(mat[i], mat[i] + max, -1);
	}
	
	
	while (m--) {
		cin >> type;
		if (type == 1) {
			cin >> a >> b;
			mat[a][b] = 0;
			mat[b][a] = 0;
		}
		else if (type == 2) {
			cin >> p >> t;
			visit[p] = 1;
			que.push(p);
			bfs(t);
		}
		
	}

	for (int i = 1; i <= n; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}
posted @ 2020-07-28 17:40  DengSchoo  阅读(750)  评论(0编辑  收藏  举报