Codeforces Round #785 div2

Round #785 (Div. 2)

A. Subtle Substring Subtraction(签到)

思路: n n n为奇数时,头大吃头,尾大吃尾,留下一个给 B o b Bob Bob,再做比较; n n n为偶数, A l i c e Alice Alice全吃必赢

C o d e : Code: Code:

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define y1 yyy
typedef long long ll;
typedef unsigned long long u64;
typedef pair<string,int> PII;
const int N=2e5+10,mod=998244353;
int t;
void solve(){
	string s;
	cin>>s;
	int n=s.size();
	if(n%2==1){
		ll ans1=0,ans2=0;
		if(s[0]>s[n-1]){
			for(int i=0;i<n-1;i++) ans1+=(s[i]-'a'+1);
			ans2=s[n-1]-'a'+1;
		}else {
			for(int i=1;i<n;i++) ans1+=(s[i]-'a'+1);
			ans2=s[0]-'a'+1;
		}
		if(ans1>ans2) {
			cout<<"Alice"<<" "<<ans1-ans2<<endl;
		}else{
			cout<<"Bob"<<" "<<ans2-ans1<<endl;
		}
	}else{
		ll ans1=0;
		for(int i=0;i<n;i++) ans1+=(s[i]-'a'+1);
		cout<<"Alice"<<" "<<ans1<<endl;
	}
}
int main(){
	read(t);
	while(t--) solve();
	return 0;
}

B. A Perfectly Balanced String?(思维)

思路:如果不是类似于 a b c a b c a . . . abcabca... abcabca...的字符串都能找出一个子串使其不包括某个字符但这个子串中存在某个字符的个数大于等于2

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define y1 yyy
typedef long long ll;
typedef unsigned long long u64;
typedef pair<string,int> PII;
const int N=2e5+10,mod=998244353;
void solve(){
	string s;cin>>s;
	set<char>st;
	for(auto i:s) st.insert(i);
	int m=st.size(),n=s.size();
	for(int i=m;i<n;i++){
		if(s[i]!=s[i-m]){
			cout<<"NO"<<endl;
			return;
		}
	}
	cout<<"YES"<<endl;
}
int main(){
	int t; cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

C. Palindrome Basis(完全背包)

思路:先预处理出所有的对称数,大约 500 500 500个,然后就是一个完全背包求方案数的裸题

C o d e : Code: Code

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define y1 yyy
typedef long long ll;
typedef unsigned long long u64;
typedef pair<string,int> PII;
const int N=4e4+10,mod=1e9+7;
int t,k;
vector<int>a;
ll dp[N];
bool check(int x){
    vector<int>q;
    q.clear();
    while(x){
        q.push_back(x%10);
        x/=10;
    }
    for(int i=0,j=q.size()-1;i<=j;i++,j--){
        if(q[i]!=q[j]) return false;
    }
    return true;
}
void solve(){
    int n;cin>>n;
    cout<<dp[n]<<endl;
}
int main(){
    cin>>t;
    for(int i=1;i<=N;i++){
        if(check(i)) a.push_back(i);
    }
    k=a.size();
    dp[0]=1;
    for(int i=0;i<k;i++){
        for(int j=a[i];j<=N-10;j++){
           dp[j]=(dp[j]+dp[j-a[i]])%mod;
        }
    }
    while(t--){
		solve();
    }
    return 0;
}

D. Lost Arithmetic Progression(数学)

思路: C C C A A A B B B的子集,因此 d c = l c m ( d a , d b ) dc=lcm(da,db) dc=lcm(da,db)
接下来判断 C C C是否全部在 B B B中出现过,需要满足下面三个条件:

if(!(st1<=st2&&ed2<=ed1)||d2%d1!=0||(st2-st1)%d1!=0)

接下来判断 A A A是否是无穷多个,满足条件为:

if(st2-d2<st1||ed2+d2>ed1)

枚举 d a da da d a da da d c dc dc的因子,对于每个满足条件的 d a da da,可以得到 A A A的种数为: d c d a ∗ d c d a \frac{dc}{da}*\frac{dc}{da} dadcdadc

C o d e : Code: Code:

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define y1 yyy
typedef long long ll;
typedef unsigned long long u64;
typedef pair<int,int> PII;
const int N=5e5+10,mod=1e9+7;
ll st1,d1,len1,st2,d2,len2;
ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
void solve(){
	cin>>st1>>d1>>len1;
	cin>>st2>>d2>>len2;
	ll ed1=st1+d1*(len1-1);
	ll ed2=st2+d2*(len2-1);
	if(!(st1<=st2&&ed2<=ed1)||d2%d1!=0||(st2-st1)%d1!=0){
		cout<<"0"<<endl;
		return ;
	}
	if(st2-d2<st1||ed2+d2>ed1) {
		cout<<"-1"<<endl;
		return ;
	}
	ll ans=0;
	for(ll i=1;i*i<=d2;i++){
		if(d2%i==0){
			if(lcm(d1,i)==d2) ans=(ans+(d2/i)*(d2/i))%mod;
			if(d2/i!=i&&lcm(d1,d2/i)==d2) ans=(ans+i*i)%mod;
		}
	}
	cout<<ans<<endl;
}
int main(){
	int t;cin>>t;
	while(t--) solve();
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学不会数据库

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值