月赛T1+T2求调
  • 板块学术版
  • 楼主XH20090229x
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/8/21 08:32
  • 上次更新2023/11/3 02:20:20
查看原帖
月赛T1+T2求调
541239
XH20090229x楼主2023/8/21 08:32

RT,月赛40+5+0+0抬走()

A:40pts

#include <iostream>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while (t--){
		int n,p;
		cin>>n>>p;
//		if (n*2<=p||p>2e5||p==1){
//			for (int i=0;i<n;i++){
//				cout<<i+1<<" "; 
//			}
//			cout<<endl;
//			continue;
//		}
		if (p==2){
			for (int i=1;i<=n;i+=2){
				cout<<i<<" ";
			}
			for (int i=2;i<=n;i+=2){
				cout<<i<<" ";
			}
			cout<<endl;
			continue;
		}
		if (p==3){
			for (int i=1;i<=n;i+=3){
				if (i+1>n){
					cout<<i<<" ";
					continue;
				}
				cout<<i<<" "<<i+1<<" "; 
			}
			for (int i=3;i<=n;i+=3){
				cout<<i<<" ";
			}
			cout<<endl;
			continue;
		}
		if (p%2==1){
			for (int i=1;i<=p/2;i++){
				for (int j=i;j<=n;j+=p){
					cout<<j<<" "<<(j/p)*p+p-i<<" ";
				}
			}
			for (int i=p;i<=n;i+=p){
				cout<<i<<" ";
			}
			cout<<endl;
			continue;
		}
		else{
			for (int i=1;i<p/2;i++){
				for (int j=i;j<=n;j+=p){
					cout<<j<<" "<<(j/p)*p+p-i<<" ";
				}
			}
			for (int i=p;i<=n;i+=p){
				cout<<i<<" ";
			}
			for (int i=p/2;i<=n;i+=p){
				cout<<i<<" ";
			}
			cout<<endl;
			continue;
		}
	}
} 

B:5pts

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	int t;
	cin>>t;
	while (t--){
		int n;
		cin>>n;
		n+=2;
		string tmp;
		cin>>tmp;
		string s=" ";
		s+=tmp;
		s+=" ";
		bool flag=false;
		while (flag==false){
			flag=true;
			for (int i=1;i<n-4;i++){
				if (tmp.substr(i,4)=="BTTB"){
					if (tmp[i-1]=='T'||tmp[i+4]=='T'){
						tmp[i]='T';
						tmp[i+1]='B';
						tmp[i+2]='B';
						tmp[i+3]='T';
						flag=false;
					}
				}
			}
		}
		int res=0;
		int tp=0;
		for (int i=0;i<n;i++){
			if (tmp[i]=='T'){
				tp++;
			} 
			else{
				res=max(res,tp);
				tp=0;
			}
			//cout<<tp<<" ";
		}
		//cout<<endl;
		//cout<<tmp<<endl;
		cout<<res<<endl;
	}
}

(B思路:从头开始扫BTTB,若发现BTTB检测左右两边是否有T,若有则操作,没有则跳过(要不然是把长度为2拆成两个长度为1),直至不能操作为止)

2023/8/21 08:32
加载中...