跳到正文

个人记录

2025年莆田市”科学月“参考答案

OITime约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年4月12日
更新
2026年4月12日
篇幅
约 2 分钟

版本

  1. v1当前

T1 2次幕

C++
#include<bits/stdc++.h>
using namespace std;
unsigned long long maxx=pow(2,63);
int main(){
	int t;
	cin>>t;
	while(t--){
		unsigned long long x,n=1;
		cin>>x;
		while(n<=x&&n>0) n*=2;
		if(n<=0) cout<<maxx<<endl;
		else cout<<n/2<<endl;
	}
    return 0;
}

T2 合唱编排

C++
#include<bits/stdc++.h>
using namespace std;
char a[100001],s[10000001];
bool check(char pre,char cur,int cnt){
	for(int i=1;i<=cnt;i++){
		if(a[i]==pre){
			a[i]=cur;
			return true;
		}
	}
	return false;
}
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>s[i];
	if(n%5!=0||s[1]!='c'||s[n+1]!='p'){
		cout<<-1;
		return 0;
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		bool f;
		if(s[i]=='c') f=check('p','c',cnt);
		else if(s[i]=='h') f=check('c','h',cnt);
		else if(s[i]=='i') f=check('h','i',cnt);
		else if(s[i]=='r') f=check('i','r',cnt);
		else if(s[i]=='p') f=check('r','p',cnt);
		else{
			cout<<-1<<endl;
			return 0;
		}
		if(!f&&s[i]=='c'){
			cnt++;
			a[cnt]='c';
		}else if(!f){
			cout<<-1<<endl;
			return 0;
		}
	}
	for(int i=1;i<=cnt;i++){
		if(a[i]!='p'){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<cnt<<endl;
    return 0;
}
原文