Codeforces Round 943 (Div. 3)

A题:

gcd\left ( x,y \right ) = gcd\left ( x - y,y \right )

gcd\left ( x - y,y \right ) + y \leq x - y \Rightarrow gcd\left ( x - y,y \right ) \leq x

y = x - 1,gcd\left ( x,x - 1 \right ) + x - 1 \leq x

\Rightarrow 1 + x - 1 \leq x

因此,令y = x - 1 为最优。

ac代码:

#include<bits/stdc++.h> 
#define ll long long
#define endl '\n' 
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 2e6 + 5;
ll t,x; 
void solve() {
	cin>>t;
	while(t--){
		cin>>x;
		cout<<x-1<<endl;
	}
}
int main() {
	ios;
	solve(); 
	return 0;
}

B题:双指针遍历即可。

ac代码:

​
#include<bits/stdc++.h> 
#define ll long long
#define endl '\n' 
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1e5 + 5;
string a,b;
int t,n,m;
void solve() {
	cin>>t;
	while(t --) {
		int i = 0,j = 0,ans = 0;
		cin>>n>>m>>a>>b;
		while(j < m) {
			if(a[i] != b[j]) j ++;
			else {
				ans ++;
				i ++;
				j ++;
			}
		}
		cout<<ans<<endl;
	}
}
int main() {
	ios;
	solve(); 
	return 0;
}

​

C题:a1取大点,直接加就行,不会超出题目范围,当时没看出来,所以我用不等式控制了一下大小。

#include<bits/stdc++.h> 
#define ll long long
#define endl '\n' 
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1e5 + 5;
int t,n,x[N];
void solve() {
	cin>>t;
	while(t --) {
		int last;
		cin>>n;
		for(int i = 2; i <= n; i ++) {
			cin>>x[i];
		}
		last = x[2] + 1;
		cout<<last;
		for(int i = 2; i <= n; i ++) {
			int k = (x[i + 1] - x[i]) / last + 1;
			last = last * k + x[i];
			cout<<" "<<last;
		}
		cout<<endl;
	}
}
int main() {
	ios;
	solve(); 
	return 0;
}

D题:

对于每名选手的最大可能获得分数,我们只要要在min(n,k)回合中找即可(证明略)。

让我们定义 𝑠𝑢𝑚𝑖 和 𝑝𝑜𝑠𝑖 :

  • 在前 𝑖 个回合中出现的位置的数值总和。
  • 如果棋手决定移动 𝑖 次,他将在哪个位置停止。

ans=\max\limits_{0\le i\le \min(n,k)}(sum_i+(k-i)a_{pos_i})

ac代码:

#include<bits/stdc++.h> 
#define ll long long
#define endl '\n' 
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 2e6 + 5;
ll t,n,k,pb,ps,p[N],a[N];
bool vst[N];
ll getsc(int s) {
	ll sum = 0,mx = 0,r = k;
	memset(vst,0,sizeof(vst));
	while(!vst[s] && r > 0) {
		vst[s] = 1;
		mx = max(mx,sum + r * a[s]);
		r --;
		sum += a[s];
		s = p[s];
	}
	return mx;
}
void solve() {
	cin>>t;
	while(t--){
		cin>>n>>k>>pb>>ps;
		for(int i = 1; i <= n; i ++) cin>>p[i];
		for(int i = 1; i <= n; i ++) cin>>a[i];
		ll B = getsc(pb),S = getsc(ps);
		if(B > S) cout<<"Bodya"<<endl;
		else if(B == S) cout<<"Draw"<<endl;
		else cout<<"Sasha"<<endl;
	}
}
int main() {
	ios;
	solve(); 
	return 0;
}

E题:

在主对角线上放置 𝑛−2 个单元格。然后在 (𝑛−1,𝑛) 和(𝑛,𝑛) 处放置两个单元格,通过这种方法,我们可以生成所有可能的曼哈顿距离。奇数距离产生于主对角线上的单元格和 (𝑛−1,𝑛) 之间。偶数距离产生于主对角线上的单元格与 (𝑛,𝑛) 之间。

ac代码:

#include<bits/stdc++.h> 
#define ll long long
#define endl '\n' 
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 2e6 + 5;
ll t,n;
void solve() {
cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n-2;i++){
		cout<<i<<" "<<i<<endl;
		}
		cout<<n-1<<" "<<n<<endl<<n<<' '<<n<<endl;
	}
}
int main() {
	ios;
	solve(); 
	return 0;
}

F题:

F题貌似是异或前缀和加二分,没做。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值