Educational Codeforces Round 147 (Rated for Div. 2)(VP-17,寒假加训)

文章介绍了三道来自CodeforcesEducationalCodeforcesRound147的编程题目,涉及字符串匹配、子数组排序以及字符分割问题,展示了在C++中解决这些算法问题的方法。
摘要由CSDN通过智能技术生成

A.首位不能是0,因此*9,否者*10;

特判只有0的

// Problem: A. Matching
// Contest: Codeforces - Educational Codeforces Round 147 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1821/problem/A
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
void Lan(){
	string s;
	cin>>s;
	int n=s.length();
	ll ans=1;
	int cnt=0;
	if(s[0]=='0'){
		cout<<0<<'\n';
		return;
	}
	for(int i=0;i<n;i++){
		if(s[i]=='?' && i!=0){
			ans*=10;
			cnt++;
		}else if(s[i]=='?' && i==0){
			ans*=9;
			cnt++;
		}
	}
	cout<<ans<<'\n';
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int q;
	cin>>q;
	while (q--) {
		Lan();
	}
	return 0;
}

B.

找到不同的,再遍历一下如果是升序那还可以延申

// Problem: B. Sort the Subarray
// Contest: Codeforces - Educational Codeforces Round 147 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1821/problem/B
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N],b[N];
void Lan(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	int l=0;
	int r=0;
	for(int i=1;i<=n;i++){
		if(a[i]!=b[i]){
			l=i;
			break;
		}
	}
	for(int i=n;i>=1;i--){
		if(a[i]!=b[i]){
			r=i;
			break;
		}
	}
	for(int i=l;i>=1;i--){
		if(b[i]>b[i+1]){
			break;
		}
		l=i;
	}
	for(int i=r;i<=n;i++){
		if(b[i-1]>b[i]){
			break;
		}
		r=i;
	}
	cout<<l<<" "<<r<<'\n';
	
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int q;
	cin>>q;
	while (q--) {
		Lan();
	}
	return 0;
}

C.

补题

// Problem: C. Tear It Apart
// Contest: Codeforces - Educational Codeforces Round 147 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1821/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
void Lan(){
	string s;
	cin>>s;
	int ans=INF;
	for(int c='a';c<='z';c++){//枚举每一个字母
		int res=0;
		int len=0;
		int n=s.size();
		for(int i=0;i<n;i++){//分段
			if(s[i]!=c){
				len++;
			}else{
				res=max(res,len);//找最大的段,一次分1/2要log2次分到1,最后再删一次即可,log2+1
				len=0;
			}
			res=max(res,len);//找最大
		}
		if(!res){
			ans=0;
			break;
		}
		ans=min(ans,(int)log2(res)+1);
		
	}
	cout<<ans<<'\n';
	
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int q;
	cin>>q;
	while (q--) {
		Lan();
	}
	return 0;
}

  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值