Codeforces Round #604 (Div. 2) 解题报告

11 篇文章 0 订阅
10 篇文章 0 订阅

https://codeforces.com/contest/1265/problem/B
A
由?,a,b,c组成的串 将?改成a,b,c使得s相邻两个字符不相等
起初有相邻相等-1
思路 特判相邻两个相等且不为?输出-1
判断i=0和i=len-1端点处 s[i]=?其余部分与左右都不相等

#include<bits/stdc++.h>
#include<string>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
#define pb push_back
#define IO ios::sync_with_stdio(false);cin.tie(0);
ll a[maxn];
ll T,n,m,f;
string s;
int main(){
	cin>>T;
	while(T--){
		cin>>s;
		ll len=s.size();
		f=0;
		for(int i=0;i<len-1;i++){
			if(s[i]==s[i+1] && s[i]!='?'){
				f=1;
				break;
			}
		}
		if(f){
			cout<<-1<<endl;
			continue;
		}
		for(int i=0;i<len;i++){
			if(s[0]=='?' && i==0){
				for(char j='a';j<='c';j++){
					if(s[1]!=j){
						s[0]=j;
						break;
					}
				}
			}
			else if(s[len-1]=='?' && i==len-1){	//必须i到这个位置才能改 不能提前改 
				for(char j='a';j<='c';j++){
					if(s[len-2]!=j){
						s[len-1]=j;
						break;
					}
				}
			}
			else if(s[i]=='?'){
				for(char j='a';j<='c';j++){
					if(s[i-1]!=j && s[i+1]!=j){
						s[i]=j;
						break;
					}
				}
			}
		}
		cout<<s<<endl;
	}
    return 0;
}

B
n<=2e5 序列 子区间包含1-m序列 m为beautiful ans[m]=1
3
6
4 5 1 3 2 6
5
5 3 1 2 4
4
1 4 3 2

output
101011
11111
1001
枚举m值 如果等于1-m的区间长度 ok

#include<bits/stdc++.h>
#include<string>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
#define pb push_back
#define IO ios::sync_with_stdio(false);cin.tie(0);
ll a[maxn],pos[maxn],ans[maxn];
ll T,n,m,f;
string s;
int main(){
	cin>>T;
	while(T--){
		cin>>n;
		
		for(int i=1;i<=n;i++){
			cin>>a[i];
			pos[a[i]]=i;
			ans[i]=0;
		}
		ll l=n+1,r=0;
		for(int i=1;i<=n;i++){
			l=min(l,pos[i]);
			r=max(r,pos[i]);
			if(r-l+1==i){
				ans[i]=1;
			}
		}
		for(int i=1;i<=n;i++){
			cout<<ans[i];
		}
		cout<<endl;
	}
    return 0;
}

C
金银铜数量不超过人数n的1半 的最大量
满足金过题数>银的过题数>铜的过题数
金人数<银 金人数<铜 银铜人数不论大小
题数递减的从金开始 记录解题一样的人数 前缀和 upper_bound一下第一个人数大于n/2的位置

#include<bits/stdc++.h>
#include<string>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
#define pb push_back
#define IO ios::sync_with_stdio(false);cin.tie(0);
ll a[maxn],vis[maxn],ans;
ll T,n,m,f,cnt,pos;
string s;
ll b[maxn],sum[maxn];
void init(ll n){
	for(int i=1;i<=n;i++){
		vis[i]=0;
	}
	cnt=0;
}
int main(){
	cin>>T;
	while(T--){
		cin>>n;
		init(n);
		for(int i=1;i<=n;i++){
			cin>>a[i];
			
		}
		cnt=1;
		b[cnt]=1;
		ans=n/2;
		pos=0;
		f=0;
		for(int i=2;i<=n;i++){
			if(a[i]!=a[i-1]){
				cnt++;
				b[cnt]=1;
			}
			else
				b[cnt]++;
		}
	//	for(int i=1;i<=cnt;i++){
	//		cout<<b[i]<<" ";
	//	}
	//	cout<<endl;
		sum[0]=0;
		for(int i=1;i<=cnt;i++){
			sum[i]=sum[i-1]+b[i];
		}
		pos=upper_bound(sum+1,sum+cnt+1,ans)-sum;
	//	cout<<pos-1<<endl;
		if(sum[pos-1]<3){
			cout<<0<<" "<<0<<" "<<0<<endl;
			continue;
		}
		else{
			ll g=b[1],s=0,z=0;
			for(int i=2;i<=pos-1;i++){
				if(sum[i]-sum[1]>g){
					s=sum[i]-sum[1];
					break;
				}
			}
			if(s==0)
				f=1;
			if(sum[pos-1]-g-s>g){
				z=sum[pos-1]-g-s;
			}
			else{
				f=1;
			}
			if(f){
				cout<<0<<" "<<0<<" "<<0<<endl;
			}
			else{
				cout<<g<<" "<<s<<" "<<z<<endl;
			}
		}
	}
    return 0;
}
### Codeforces 2045C Saraga Problem Explanation The provided references do not contain information regarding the specific problem "Saraga" with ID 2045C from Codeforces. However, based on common practices for solving problems on platforms like Codeforces, a structured approach to understanding and potentially solving this problem involves several key steps. #### Understanding the Problem Statement To effectively tackle any competitive programming challenge, comprehending the exact requirements as outlined in the official problem statement is crucial. For an unspecified problem such as "Saraga," one should start by carefully reading through all sections including constraints, inputs, outputs, examples, and notes available directly from the source at [Codeforces](https://codeforces.com/) under contest number 2045, problem C[^1]. #### Analyzing Constraints Typically, analyzing given limits helps determine which algorithms might fit within those boundaries efficiently. Problems often specify maximum values for variables used in calculations or array sizes that influence algorithm choice significantly. #### Identifying Patterns Through Examples Examining sample cases usually provides insights into how solutions behave across different scenarios. This step aids immensely when formulating hypotheses about underlying patterns or properties exploited during implementation. #### Formulating Hypotheses Based on Similarities With Known Concepts Given no direct reference material exists specifically addressing "Saraga," drawing parallels between its description—if accessible—and other well-documented topics could offer valuable clues towards crafting effective strategies. Bitwise operations have been mentioned extensively throughout previous discussions; therefore, considering their applicability remains reasonable depending upon actual task specifications[^5]. ```cpp // Example pseudo-code structure without concrete logic due to lack of detailed problem definition. #include <bits/stdc++.h> using namespace std; int main() { // Placeholder code block illustrating general setup rather than precise functionality related to 'Saraga'. } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值