Codeforces Round #685 (Div. 2) 赛后题解

本文总结了多种编程竞赛中常见的解题思路与技巧,包括快速幂运算、字符串匹配、数组操作及博弈论分析等,通过具体代码示例展示了如何高效解决实际问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这场昨晚没打,早上补的,错过了一场上分场
a.1,2,3特殊处理,其他奇数和偶数下降次数分别为2,3

#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 1e5 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a)%mod;
		a = (a * a)%mod;
		b>>=1;
	}
	return (ans%mod);
}
inline int read()
{
	int x = 0, flag = 1;
	char c = getchar();
	while(c < '0' && c > '9') {if(c == '-') flag = -1, c = getchar();}
	while(c >= '0' && c <= '9') {x = x * 10 + c - '0', c = getchar();}
	return x * flag;
}
typedef pair<int,int> pii;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	int t ;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		if(n  == 1){
			cout<<0<<endl;
			continue;
		}
		if(n == 2){
			cout<<1<<endl;
			continue;
		}
		if(n % 2 == 0 || n == 3){
			cout<<2<<endl;
			continue;
		}
		cout<<3<<endl;
	}
	return 0;
}

b.只需要知道s[l]前面是否存在s[l]或者s[r]后面是否存在s[r]

#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 100 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a)%mod;
		a = (a * a)%mod;
		b>>=1;
	}
	return (ans%mod);
}
inline int read()
{
	int x = 0, flag = 1;
	char c = getchar();
	while(c < '0' && c > '9') {if(c == '-') flag = -1, c = getchar();}
	while(c >= '0' && c <= '9') {x = x * 10 + c - '0', c = getchar();}
	return x * flag;
}
typedef pair<int,int> pii;
char s[N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		int n,q;
		cin>>n>>q;
		cin>>(s + 1);
		for(int i = 1;i <= q;i++){
			int l,r;
			cin>>l>>r;
			bool f = false;
			for(int j = l - 1;j >= 1;j--)if(s[j] == s[l])f = true;
			for(int j = r + 1;j <= n;j++)if(s[j] == s[r])f = true;
			if(f)cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		
	}
	return 0;
}

c.瞎搞,找规律

#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 1e6 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a)%mod;
		a = (a * a)%mod;
		b>>=1;
	}
	return (ans%mod);
}
inline int read()
{
	int x = 0, flag = 1;
	char c = getchar();
	while(c < '0' && c > '9') {if(c == '-') flag = -1, c = getchar();}
	while(c >= '0' && c <= '9') {x = x * 10 + c - '0', c = getchar();}
	return x * flag;
}
typedef pair<int,int> pii;
char a[N],b[N];
int cnta[26],cntb[26];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		int n,k;
		for(int i = 0;i<26;i++)cnta[i] = cntb[i] = 0;
		cin>>n>>k;
		cin>>(a+1);
		cin>>(b+1);
		for(int i = 1;i <= n;i++){
			cnta[a[i] - 'a']++;
			cntb[b[i] - 'a']++;
		}
		bool f = true;
		int res = 0;
		for(int i = 0;i < 26;i++){
			if(abs(cnta[i] - cntb[i])% k != 0){
				f = false;break;
			}
			if(cnta[i] - cntb[i] < 0){
				if(res < abs(cnta[i] - cntb[i])){
					f = false;
					break;
				}
				res -= abs(cnta[i] - cntb[i]);
				
				
			}
			if(cnta[i] - cntb[i] > 0){
				 res += abs(cnta[i] - cntb[i]);
			}
					
		}
		if(f)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	} 
	return 0;
}

d.博弈论,显然,画一下决策树就知道,两个玩家必然能强制性的达到(x * k,(x + 1) * k) 或((x+1) * k,x * k的位置,分析一下这种局面对谁有利即可

#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 1e5 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a)%mod;
		a = (a * a)%mod;
		b>>=1;
	}
	return (ans%mod);
}
inline int read()
{
	int x = 0, flag = 1;
	char c = getchar();
	while(c < '0' && c > '9') {if(c == '-') flag = -1, c = getchar();}
	while(c >= '0' && c <= '9') {x = x * 10 + c - '0', c = getchar();}
	return x * flag;
}
typedef pair<int,int> pii;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		 ll d,k;
		 cin>>d>>k;
		 ll L = 1,ans = 0;
		 while(1){
		 	if(2 * (L * k) *(L * k) <= d * d){
		 		ans = L * k;
			 }else break;
			 L++;
		 }
		 //debug(ans);
		 if((ans + k) * (ans + k) + ans * ans <= d * d)
		 	cout<<"Ashish"<<endl;
		else cout<<"Utkarsh"<<endl;
	}
	return 0;
}

e1&e2,可以通过n - 1次询问,问出x[1] ^ x[i],i∈[2,n],那么只需要知道x[1]便可求解,如果存在两值相等,他们的异或x[1]值是相等的,再询问这两个位置的相与的值便可知道这两个的值,便可求得x[1]。如果不存在相等的值,说明他们的值是严格分布在[1,2^n-1]之间,那么必存在一个值异或x[1] == 1,高位相同,询问它们相与的值可以得到除第零位的所有值,x[1]第零位还不得而知,这时只需要再问一下与x[1]异或第零位为零的值和x[1]相与的值便可知道x[1]的第零位。详见代码:

#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 1e5 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
const int mod = 998244353;
ll fast_pow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1)ans = (ans * a)%mod;
		a = (a * a)%mod;
		b>>=1;
	}
	return (ans%mod);
}
inline int read()
{
	int x = 0, flag = 1;
	char c = getchar();
	while(c < '0' && c > '9') {if(c == '-') flag = -1, c = getchar();}
	while(c >= '0' && c <= '9') {x = x * 10 + c - '0', c = getchar();}
	return x * flag;
}
typedef pair<int,int> pii;
int a[N];

map<int,int> st;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	int n,x = 0,y;
	cin>>n;
	st[0] = 1;
	for(int i = 2;i <= n;i++){
		cout<<"XOR "<<1<<" "<<i<<endl;
		cin>>a[i];
		if(st[a[i]] && !x){
			cout<<"AND "<<st[a[i]]<<" "<<i<<endl;
			cin>>y;
			x = i;
		}
		st[a[i]] = i;
	}
	if(x){
		a[1] = a[x] ^ y;
	}else{
		cout<<"AND "<<1<<" "<<st[1]<<endl;
		cin>>a[1];
		for(auto it:st){
			if(it.fi & 1 == 1 || it.se == 1)continue;
			cout<<"AND "<<1<<" "<<it.se<<endl;
			int c;
			cin>>c;
			if(c&1)a[1]^=1;
			break;
		}
	}
	cout<<"! "<<a[1];
	for(int i = 2;i <= n;i++)
		cout<<" "<<(a[i] ^ a[1]);
	cout<<endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值