2022年蓝桥杯省赛C++B组题解-创新互联

题单传送门

成都创新互联秉承实现全网价值营销的理念,以专业定制企业官网,成都做网站、网站制作、成都外贸网站建设小程序开发,网页设计制作,手机网站开发,全网整合营销推广帮助传统企业实现“互联网+”转型升级专业定制企业官网,公司注重人才、技术和管理,汇聚了一批优秀的互联网技术人才,对客户都以感恩的心态奉献自己的专业和所长。九进制转十进制
#include#include 
#include#includeusing namespace std;
 
int main(){int a = 2022, cnt = 1, ans = 0;
    while(a){ans += a % 10 * cnt;
        cnt *= 9;
        a /= 10;
    }
    cout<< ans<< endl;
    return 0;
}

在这里插入图片描述

顺子日期
#include#include 
#include#includeusing namespace std;
 
int main(){cout<< 14<< endl;
    return 0;
}

在这里插入图片描述

刷题统计
#include#include 
#include#includeusing namespace std;
 
int main(){long long a, b, n;
    cin >>a >>b >>n;
    long long week = 5 * a + 2 * b;
    long long ans = n / week * 7;
    n %= week;
    for(int i = 1; i<= 7; ++i){if(n<= 0){cout<< ans<< endl;
            return 0;
        }
        switch(i){case 1:
        case 2:
        case 3:
        case 4:
        case 5:
            n -= a;
            break;
        case 6:
        case 7:
            n -= b;
        }
        ans++;
    }
    cout<< ans<< endl;
    return 0;
}

在这里插入图片描述

修剪灌木
#include#include 
#include#include#includeusing namespace std;
 
int main(){int n;
    cin >>n;
    vectorv;
    for(int i = 1; i<= n / 2; ++i){int t = 2 * max(n - i, i);
        cout<< t<< endl;
        v.push_back(t);
    }
    if(n % 2 == 1) cout<< n - 1<< endl;
    for(int i = v.size() - 1; i >= 0; --i){cout<< v[i]<< endl;
    }
    return 0;
}

在这里插入图片描述

X进制减法
#include#include 
#include#includeusing namespace std;
typedef long long LL;
const LL N = 1e5 + 10, MOD = 1000000007;

LL a[N], b[N];

int main(){int n, ma, mb;
	cin >>n >>ma;
	
	for(int i = ma - 1; i >= 0; --i) cin >>a[i];	
	
	cin >>mb;
	for(int i = mb - 1; i >= 0; --i) cin >>b[i];
	
	LL ans = 0;
	for(int i = max(ma, mb) - 1; i >= 0; --i)
		ans = (ans * max({1LL * 2 , a[i] + 1 , b[i] + 1}) + a[i] - b[i]) % MOD;
	
	cout<< ans<< endl;
	return 0;
}

在这里插入图片描述

统计子矩阵
#include#include 
#include#includeusing namespace std;
typedef long long LL;
const int N = 510;
 
LL s[N][N];
 
int main() {LL n, m, k;
    cin >>n >>m >>k;
 
    for (int i = 1; i<= n; ++i)
        for (int j = 1; j<= m; ++j) {cin >>s[i][j];
            s[i][j] += s[i - 1][j];
        }
 
    LL ans = 0;
    for (int i = 1; i<= n; ++i)
        for (int j = i; j<= n; ++j)
            for (int l = 1, r = 1, sum = 0; r<= m; ++r) {sum += s[j][r] - s[i - 1][r];
                while (sum >k) {sum -= s[j][l] - s[i - 1][l];
                    l++;
                }
                ans += r - l + 1;
            }
 
    cout<< ans<< endl;
    return 0;
}

在这里插入图片描述

积木画
#include#include 
#include#includeusing namespace std;
typedef long long LL;
const int N = 1e7 + 10, mod = 1000000007;

LL f[N][3];

int main() {int n;
	cin >>n;
	
	f[0][0] = 1;
	for (int i = 1; i<= n; i++) {f[i][0] = (f[i - 1][0] + f[i - 1][1] + f[i - 1][2]) % mod;
		if (i >= 2) {	f[i][0] = (f[i][0] + f[i - 2][0]) % mod;
			f[i][1] = (f[i - 2][0] + f[i - 1][2]) % mod;
			f[i][2] = (f[i - 2][0] + f[i - 1][1]) % mod;
		}
	}
	
	cout<< f[n][0] % mod<< endl;
	return 0;
}

在这里插入图片描述

李白打酒加强版
#include#include 
#include#includeusing namespace std;
const int N = 200, mod = 1000000007;

int f[N][N][N];

void solve() {int n, m;
	cin >>n >>m;
	memset(f, 0, sizeof f);
	f[0][0][2] = 1;
	for (int i = 1; i< n + m; ++i)
		for (int j = 0; j< m; ++j)
			for (int k = 0; k<= m; ++k) {		if (!(k & 1)) f[i][j][k] = (f[i][j][k] + f[i - 1][j][k >>1]) % mod;
				if (j >0) f[i][j][k] = (f[i][j][k] + f[i - 1][j - 1][k + 1]) % mod;
			}
	cout<< f[n + m - 1][m - 1][1]<< endl;
}

int main() {int T;
	cin >>T;
	while (T--) {solve();
	}
	return 0;
}

在这里插入图片描述

砍竹子
#include#include 
#include#include#include#include#includeusing namespace std;
typedef pairPII;

void solve() {long long n, x;
	cin >>n;
	priority_queue, less>q;
	for(int i = 1; i<= n; ++i){cin >>x;
		if(x != 1) q.push({x, i});
	}
	long long ans = 0;
	while(!q.empty() && q.top().first != 1){auto t = q.top();
		q.pop();
		long long cnt = 1, num = sqrt(t.first / 2 + 1);
		if(num != 1) q.push({num, t.second});
		while(!q.empty() && q.top().first == t.first && q.top().second == t.second - cnt){	cnt++;
			auto temp = q.top();
			q.pop();
			if(num != 1) q.push({num, temp.second});
		}
		ans++;
	}
	cout<< ans<< endl;
}

int main() {solve();
	return 0;
}

在这里插入图片描述

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


本文名称:2022年蓝桥杯省赛C++B组题解-创新互联
转载来于:http://ybzwz.com/article/gojpe.html