第十五届蓝桥杯大赛软件赛省赛C/C++ 研究生组

A

审题!
“连续的 k 次正确敲击,如果任意连续的两次敲击间间隔时间都小于等于 1s,那么我们称这是一次K 连击”
=>k连击要求:

  • 连续的正确操作
  • 任意相邻的两次操作时间间隔不超过1s

则时间间隔少于1s但是中间有错误操作的不满足连续的正确操作。转化问题时一定注意是否完全等价,是否有遗漏的特殊情况。

#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 2e3 + 10;
struct logs{
	char a, b;
	ll t;
}ls[N];

bool cmp(logs l1, logs l2){
	return l1.t < l2.t;
} 
int main(){
//	int n = 2000, k = 1, num = 0;
//	char ta, tb;
//	ll tt;
//	for(int i = 0; i < n; i++){
//		scanf("%c %c %lld", &ls[i].a, &ls[i].b, &ls[i].t);
//		getchar();
//	}
//	sort(ls, ls + n, cmp);
//	for(int i = 0; i < n; i++){
//		if(ls[i].a != ls[i].b) {//中断,统计当前连击数量
//			k = max(num, k);
//			num = 0;
//		}
//		else if(abs(ls[i].t - ls[i - 1].t) > 1000){
//			k = max(num, k);
//			num = 1;
//		}
//		else num++;
//	}
//	printf("%d", k);
	cout << 9; 
	return 0;
} 

B

数据很大暴力是不可能的了,打表发现大于等于10的B(i)都可以整除100,问题转化为找到A(i)=i(i+1)/2整除100的数,即i(i+1)%200 == 0
再次打表发现每1e3个里面有20个的规律,则n/100020再加上n/10001000到n之间的数量,是大于9之后的总数。
小于等于9的里面还有一个A(1) - B(1) = 0,A(3) - B(3) = 0也满足

#include<iostream>
using namespace std;
typedef long long ll;

bool judge(ll x){
	ll two = 3, five = 2, t = x + 1;
	while(two && x % 2 == 0){
		x /= 2;
		two--;
	}
	while(five && x % 5 == 0){
		x /= 5;
		five--;
	}
	
	while(two && t % 2 == 0){
		t /= 2;
		two--;
	}
	while(five && t % 5 == 0){
		t /= 5;
		five--;
	}
	if(!two && !five) return true;
	return false;
}

int main(){
	ll n = 2024041331404202L, ans = n / 1000 * 20;
	for(ll i = 2024041331404001L; i <= n; i++){//计算大于10的个数 (用规律) 
		if(i % 200 == 0 || (i + 1) % 200 == 0 || judge(i)) ans++;
	}
	cout << ans + 2;//1,3也满足,即计入小于10的个数 (打表判断) 
	return 0;
} 

C

#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int a[N], mp[10] = {1, 0, 0, 0, 1, 0, 1, 0, 2, 1};

bool cmp(int a, int b){
	int fa = 0, fb = 0, ta = a, tb = b;
	if(!ta) fa = mp[0];
	if(!tb) fb = mp[0];
	while(ta){
		fa += mp[ta%10];
		ta /= 10;
	}
	while(tb){
		fb += mp[tb%10];
		tb /= 10;
	}
	if(fa != fb) return fa < fb;
	return a < b;
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", a + i);
	}
	sort(a, a + n, cmp);
	for(int i = 0; i < n; i++){
		printf("%d ", a[i]);
	}
	return 0;
} 

D

AC 20%

#include<iostream>
#include<string>
using namespace std;
typedef long long ll;
const int N = 210, M = 110;
string s[N];
bool st[N]; 
int main(){
	int n, m, ans = 0, cur, p;
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> s[i];
		s[i] = " " + s[i] + s[i];
	}
	st[1] = true;
	for(int i = 1; i <= n; i++){
		cur = 0;
		for(int j = i + 1; j <= n; j++){
			int dp[M][M] = {0};
			for(int x = 1; x <= 2*m; x++){
				for(int y = 1; y <= 2*m; y++){
					if(s[i][x] == s[j][y]) {
						dp[x][y] = dp[x - 1][y - 1] + 1;
						if((st[i] || st[j]) && cur < dp[x][y]){
							p = j;
							cur = max(cur, dp[x][y]);
						}
					}
					else dp[x][y] = 0;
				}
			}
		}
		if(cur > m) cur = m;
		st[p] = true;
		ans += cur;
	}
	cout << ans;
	return 0;
} 

E

#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int a[N];
int p, n, m;
ll ans = 0;
int main(){
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; i++){
		scanf("%d", a + i);
	}
	sort(a, a + n);
	if(a[0] >= 0 || a[n - 1] <= 0) {//全是非负数 
		for(int i = n - 1; i >= 0; i--){
			if(abs(a[i]) <= m){
				ans = i + 1;
				break; 
			}
		}
	}
	else{
		p = n;
		for(int i = 0; i < n; i++){
			if(!a[i] || (a[i] > 0 && p == n)){
				 p = i;
				 break;
			}
		}
		for(ll l = 0; l < p; l++){
			for(ll r = p; r < n; r++){
				if(2*abs(a[l])+a[r] > m) continue;
				ans = max(ans, r - l + 1);
			}
		}
	}
	printf("%lld", ans);
	return 0;
} 

F

G

AC50%

#include<iostream>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int x[N], f[N];
int main(){
	int n, ans = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &x[i]);
	}
	for(int i = 0; i < n; i++){
		scanf("%d", &f[i]);
	}
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			if(f[i] != j && f[j] != i) ans = max(ans, x[i]^x[j]);
		}
	}
	printf("%d", ans);
	return 0;
} 

H

I

G

### 关于第十五届蓝桥杯2024 C/C++ A大学软件的信息 #### 比题目概述 根据已有的信息,第十五届蓝桥杯软件C/C++大学A的比题目尚未完全公开。然而,在某些参者的分享中提到,部分试题涉及算法设计与优化[^1]。例如,“合法密码”问题是其中的一道典型考题,其核心在于字符串处理和合法性验证逻辑的设计[^2]。 #### 时间复杂度的要求 对于一些具体问题,如图论相关的内容,时间效率成为评判标准之一。有记录显示,针对特定类型的输入数据结构(比如边的关系),即使采用较为基础的双重循环实现方法,也能满足竞设定的时间限制——通常为3秒以内完成运算[^3]。 #### 参加者的学习计划建议 为了更好地备战此类事,一位昵称为“牛友”的选手提出了自己的学习规划:利用假期集中精力复习数学基础知识,并通过参与各类线上编程挑战来积累实战经验,目标是从当前学科成功转换至计算机科学领域继续深造。 ```cpp // 示例代码片段展示如何判断简单条件下的合法密码 bool isValidPassword(const std::string& password){ bool hasUpper = false; bool hasLower = false; bool hasDigit = false; if(password.length() < 8 || password.length() > 16) return false; for(char c : password){ if(isupper(c)) hasUpper=true; else if(islower(c)) hasLower=true; else if(isdigit(c)) hasDigit=true; // 假设不允许特殊字符作为简化版规则的一部分 if(!isalnum(c)) return false; } return (hasUpper && hasLower && hasDigit); } ``` 上述函数仅为示意性质,实际比中可能需要考虑更复杂的约束条件以及边界情况测试。 #### 总结 综上所述,参加蓝桥杯这样的高水平程序设计大赛不仅考验选手的技术功底,还需要合理安排训练周期并不断调整策略适应新变化。希望每位热爱编码的人都能在这一过程中收获成长!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值