Codeforces Round 906 (Div. 2) (VP-4,寒假加训)

文章讨论了四道来自CodeforcesRound906(Div.2)的问题,涉及字符串操作(交替数组、字符串匹配、字符串转换和连接优化),以及一些算法技巧如使用map、set和递归。

VP时间

A.7,8,7

111111111只有一个元素

小大小 

78787878787交替数组

用桶计数还需要要求有的两个数是,桶太大了?

计算一个num1,n-num1=num2?

用set只能去重,

用map

size>2:NO

size==1:YES

size==2:且abs(num1-num2)<=1:YES,否则:NO

1.n&1小的数要多一个

2.! n&1一样大

综合abs(num1-num2)<=1;

1.wa2

2.ac

B.是否可以变成交替0101010

1.看原字符串是不是

2.看插入那段是不是

6 7

101100

1010101

说明插入只能修复一种情况

!100插入10:10100:

模拟应该是看插入段的开头,如果是1就插在0后面(这种情况是00连在一起,因此插入的最后一个必须是1),如果是0就插在1后面(11),最后一个是0.

3.检查插入那段是不是头尾相等

1.ac

C.条件是1,0数字数量要相同,应该是对应(1->0,0->1)(首尾对应)

插入01

1.先判断原字符串是否满足

2.再判断1,0个数是否一样

3.再判断是不是1->1,0->0(全部满足)

4.0101011100

0-0,因此要后面插入01=> (0-1)

然后看10101110不断分下去

递归到size==0(while)

break条件s.size()==0

如果重复上次的字符串等于分完的字符串就无法变好(cnt>=300)

加个计时器即可判断

1.ac

D.

从(1开始连一般是最优的)

1->指向的优先级(找a[i]最大)

应该是sum+a[i]>=j*c,sum>=j*c-a[i];优先级应该是j*c-a[i];越小越好

弄个结构体存下标,和数值.

1.wa3

2.ac(开ll)

E.没思路,前缀和?

题解

A.

// Problem: A. Doremy's Paint 3
// Contest: Codeforces - Codeforces Round 906 (Div. 2)
// URL: https://codeforces.com/contest/1890/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//へ     /|
//  /\7    ∠_/
//  / │   / /
// │ Z _,< /   /`ヽ
// │     ヽ   /  〉
//  Y     `  /  /
// イ● 、 ●  ⊂⊃〈  /
// ()  へ    | \〈
//  >ー 、_  ィ  │ //
//  / へ   / ノ<| \\
//  ヽ_ノ  (_/  │//
//	  7       |/
//	  >―r ̄ ̄`ー―_
#include <iostream>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
void solve() {
	int n;
	cin>>n;
	map<int,int>mp;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		mp[x]++;
	}
	if(mp.size()>2){
		cout<<"No"<<'\n';
	}else if(mp.size()==1){
		cout<<"Yes"<<'\n';
	}else{
		int ans[2],k=0;
		for(auto i : mp){
			ans[k++]=i.second;
		}
		if(abs(ans[0]-ans[1])<=1){
			cout<<"Yes"<<'\n';
		}else{
			cout<<"No"<<'\n';
		}
	}
	
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int q;
	cin >> q;
	while (q--) {
		solve();
	}

	return 0;
}

B.

// Problem: B. Qingshan Loves Strings
// Contest: Codeforces - Codeforces Round 906 (Div. 2)
// URL: https://codeforces.com/contest/1890/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//へ     /|
//  /\7    ∠_/
//  / │   / /
// │ Z _,< /   /`ヽ
// │     ヽ   /  〉
//  Y     `  /  /
// イ● 、 ●  ⊂⊃〈  /
// ()  へ    | \〈
//  >ー 、_  ィ  │ //
//  / へ   / ノ<| \\
//  ヽ_ノ  (_/  │//
//	  7       |/
//	  >―r ̄ ̄`ー―_
#include <iostream>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
void solve() {
	bool one=0;
	int n,m;
	cin>>n>>m;
	string sn;
	cin>>sn;
	string sm;
	cin>>sm;
	char ans=sm[0];
	for(int i=0;i<n-1;i++){
		if(sn[i]==sn[i+1]){
			one=true;
			if(sn[i]==ans){
				cout<<"No"<<'\n';
				return;
			}
		}
	}
	if(!one){
		cout<<"Yes"<<'\n';
		return;
	}
	for(int i=0;i<m-1;i++){
		if(sm[i]==sm[i+1]){
			cout<<"No"<<'\n';
			return;
		}
	}
	if(sm[0]==sm[m-1]){
		cout<<"Yes"<<'\n';
	}else{
		cout<<"No"<<'\n';
	}

}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int q;
	cin >> q;
	while (q--) {
		solve();
	}

	return 0;
}

C.

// Problem: C. Qingshan Loves Strings 2
// Contest: Codeforces - Codeforces Round 906 (Div. 2)
// URL: https://codeforces.com/contest/1890/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//へ     /|
//  /\7    ∠_/
//  / │   / /
// │ Z _,< /   /`ヽ
// │     ヽ   /  〉
//  Y     `  /  /
// イ● 、 ●  ⊂⊃〈  /
// ()  へ    | \〈
//  >ー 、_  ィ  │ //
//  / へ   / ノ<| \\
//  ヽ_ノ  (_/  │//
//	  7       |/
//	  >―r ̄ ̄`ー―_
#include <iostream>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
void solve() {
	int n;
	cin>>n;
	string s;
	cin>>s;
	int temp1=n;
	int temp2=temp1;
	int temp3=0;
	vector<int>v;
	int cnt=0;
	while(1){
		if(s[0]==s[temp1-1] && s[0]=='0'){
			s+="01";
			s=s.substr(1,temp1);
			v.push_back(temp2);
			temp3++;
			temp2++;
		}else if(s[0]==s[temp1-1] && s[0]=='1'){
				s="01"+s;
				s=s.substr(1,temp1);
				v.push_back(temp3);
				temp3++;
				temp2++;
		}else{
			temp1-=2;
			s=s.substr(1,temp1);
			temp2--;
			temp3++;
		}
		cnt++;
		if(cnt==300){
			cout<<"-1"<<'\n';
			return;
		}
		if(s.size()==0){
			break;
		}
	}
	cout<<v.size()<<'\n';
	for(auto i:v){
		cout<<i<<" ";
	}
	cout<<'\n';
	
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int q;
	cin >> q;
	while (q--) {
		solve();
	}

	return 0;
}

D.

// Problem: D. Doremy's Connecting Plan
// Contest: Codeforces - Codeforces Round 906 (Div. 2)
// URL: https://codeforces.com/contest/1890/problem/D
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//へ     /|
//  /\7    ∠_/
//  / │   / /
// │ Z _,< /   /`ヽ
// │     ヽ   /  〉
//  Y     `  /  /
// イ● 、 ●  ⊂⊃〈  /
// ()  へ    | \〈
//  >ー 、_  ィ  │ //
//  / へ   / ノ<| \\
//  ヽ_ノ  (_/  │//
//	  7       |/
//	  >―r ̄ ̄`ー―_
#include <iostream>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e5+9;
ll n,c;
struct node{
	ll num,index;
}a[N];
bool cmp(node a,node b){
	return a.index*c-a.num<b.index*c-b.num;
}
void solve() {
	cin>>n>>c;
	for(int i=1;i<=n;i++){
		cin>>a[i].num;
		a[i].index=i;
		
	}
	sort(a+2,a+1+n,cmp);
	ll sum=a[1].num;
	for(int i=2;i<=n;i++){
		ll ans=c*a[i].index;
		if(sum+a[i].num>=ans){
			sum+=a[i].num;
		}else{
			cout<<"No"<<'\n';
			return;
		}
	}
	cout<<"Yes"<<'\n';

}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int q;
	cin >> q;
	while (q--) {
		solve();
	}

	return 0;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值