Codeforces Round #834 (Div. 3)

A:思维

题意:给定一个字符串,问是否是若干个Yes的子串

思路:我们用一个单串“Yes”去扫描字符串,看是否能够依次匹配。注意,字符串的开头部分需要特殊处理一下。具体看代码:

代码:

#include<bits/stdc++.h>
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int N=2e5+10;
typedef pair<int,int>PII;

inline void solve(){
	string s;cin>>s;
	if(s[0]!='Y'&&s[0]!='e'&&s[0]!='s'){//特判
		cout<<"NO\n";return;
	}
//特殊化处理
	if(s[0]=='e') s="Y"+s;
	else if(s[0]=='s') s="Ye"+s;
	int n=s.size();
	s="*"+s;
	string a="Yes";//单串
	bool ok=false;
	for(int i=1,l=0;i<=n;i++){
		if(a[l]!=s[i]){
			cout<<"NO\n";return;
		}
		l++;
		if(l==3) l=0;
	}
	cout<<"YES\n";
}


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

B: 枚举

题意:定义了一个序列:该序列中的数为1-n,且只能出现一次。给定了一个长度为n的残缺数组,给定了丢失数字的和。问能否还原一个序列?

思路:先通过和,找出丢失的数,再判断最终的序列是否为定义的序列。

代码:

#include<bits/stdc++.h>
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int N=2e5+10;
typedef pair<int,int>PII;

inline void solve(){
	map<int,int>mp;
	int n,s;cin>>n>>s;
	int maxx=0;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		mp[x]++;
		maxx=max(maxx,x);
	}
	int sum=0;
	for(int i=1;i<=s;i++){
		if(mp.count(i)) continue;
		sum+=i;mp[i]++;
		maxx=max(maxx,i);
		if(sum>=s) break;
	}
	if(sum==s){
		for(int i=1;i<=maxx;i++){
			if(!mp.count(i)){
				cout<<"NO\n";return;
			}
		}
		cout<<"YES\n";
	}
	else cout<<"NO\n";
}

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

C:

 此题来自:Codeforces Round #834 (Div. 3) A - G - 知乎

代码:

#include<bits/stdc++.h>
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int N=2e5+10;
typedef pair<int,int>PII;

inline void solve(){
	int l,r,x,a,b;cin>>l>>r>>x>>a>>b;
	int ans;
	if(a==b) ans=0;
	else if(abs(a-b)>=x) ans=1;
	else{
		if(b-l>=x and r-b>=x){
			if(a-l>=x or r-a>=x) ans=2;
			else ans=-1;
		}
		else if(b-l>=x){
			if(a-l>=x) ans=2;
			else if(r-a>=x) ans=3;
			else ans=-1;
		}
		else if(r-b>=x){
			if(r-a>=x) ans=2;
			else if(a-l>=x) ans=3;
			else ans=-1;
		}
		else ans=-1;
	}
	cout<<ans<<"\n";
}

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

D:

代码:

#include<bits/stdc++.h>
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int N=2e5+10;
typedef pair<int,int>PII;

inline void solve(){
	int n, m;cin >> n >> m;
	int cnt2 = 0, cnt5 = 0, x = n;
	while(x % 2 == 0) x /= 2, cnt2++;
	while(x % 5 == 0) x /= 5, cnt5++;
	int ans = 0;
	for(int i = min(cnt2, cnt5); ; i++){
		int t = 1;
		for(int j = 0; j < i - cnt2; j++) t *= 2;
		for(int j = 0; j < i - cnt5; j++) t *= 5;
		if(t > m) break;
		ans = m / t * t * n;
	}
	cout << ans << endl;
}

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值