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 ;
}