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

本文介绍了Codeforces教育性比赛第86轮中的三个问题(A、B、C)的解决方案,涉及数学运算、字符串处理、周期性计算以及前缀和的使用。参赛者需解决关于数组操作、二进制周期和计算最小值的问题。
摘要由CSDN通过智能技术生成

A.

得开ll

// Problem: A. Road To Zero
// Contest: Codeforces - Educational Codeforces Round 86 (Rated for Div. 2)
// URL: https://codeforces.com/group/RAx5fiilkP/contest/1342/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 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(){
	ll x,y;
	cin>>x>>y;
	ll a,b;
	cin>>a>>b;
	if(a+a>b){
		cout<<min(x,y)*b+abs(x-y)*a<<'\n';
	}else{
		cout<<(x+y)*a<<'\n';
	}
	
		
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int q;
	cin>>q;
	while (q--) {
		Lan();
	}
	return 0;
}

B.

周期要么是1要么是2

// Problem: B. Binary Period
// Contest: Codeforces - Educational Codeforces Round 86 (Rated for Div. 2)
// URL: https://codeforces.com/group/RAx5fiilkP/contest/1342/problem/B
// 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;
const int N = 2e6 + 9;
int a[N];
void Lan(){
	string t;
	cin>>t;
	int n=t.length();
	int cnt0=0;
	for(int i=0;i<n;i++){
		if(t[i]=='0'){
			cnt0++;
		}
	}
	int cnt1=n-cnt0;
	if(cnt0 && cnt1){
		if(t[0]=='0'){
			for(int i=1;i<=2*n;i++){
				if(i&1){
					cout<<0;
				}else{
					cout<<1;
				}
			}
			cout<<'\n';
			return;
		}else{
			for(int i=1;i<=2*n;i++){
				if(i&1){
					cout<<1;
				}else{
					cout<<0;
				}
			}
			cout<<'\n';
			return;
		}
	}
	if(cnt1 && !cnt0){
		cout<<t<<'\n';
		return;
	}
	if(!cnt1 && cnt0){
		cout<<t<<'\n';
		return;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int q;
	cin>>q;
	while (q--) {
		Lan();
	}
	return 0;
}

C.

建议打表找规律然后找到周期是lcm(a,b)

前缀和处理一个lcm(a,b)的范围

那就可以知道l在有几个数,r能有几个数,x不能到l-1,减去即可

// Problem: C. Yet Another Counting Problem
// Contest: Codeforces - Educational Codeforces Round 86 (Rated for Div. 2)
// URL: https://codeforces.com/group/RAx5fiilkP/contest/1342/problem/C
// Memory Limit: 256 MB
// Time Limit: 3500 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=1e5+9;
ll prefix[N];
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll a,b,q;
ll work(ll x){
	ll num=x/lcm(a,b);
	ll ans=(num*prefix[lcm(a,b)])+prefix[x%lcm(a,b)];//num个周期+剩余数
	return ans;
}
void Lan(){
	cin>>a>>b>>q;
	for(int i=1;i<=lcm(a,b);i++){
		prefix[i]=prefix[i-1]+(i%a%b!=i%b%a);//计算一个周期
	}
	while(q--){
		ll l,r;
		cin>>l>>r;
		cout<<work(r)-work(l-1)<<" ";//l-1 x到不了得减去
	}
	cout<<'\n';
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int t;
	cin>>t;
	while (t--) {
		Lan();
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值