【LGR-148-Div.3】洛谷基础赛 #1 & MGOI Round I
P9502 『MGOI』Simple Round I | A. 魔法数字
思路
通过题目信息,可以很容易想出用暴力枚举的方式一个个去枚举这个整数m,当发现\(2^m\)>=n时,输出上一个整数m。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxN=100000+10;
int n;
int cnt=0;
int a[maxN];
int main(){
cin>>n;
int m;
for(int i=1;;i++){
if(i%2==0){
cnt++;
int c=pow(2,i);
a[cnt]=i;
if(c>=n){
cout<<a[cnt-1];
return 0;
}
}else{
continue;
}
}
return 0;
}
P9503 『MGOI』Simple Round I | B. 魔法照相馆
思路
采用模拟的策略,使用一个bool数组来实时记录当前幕布拉上或拉下的一个状态,然后根据题目要求,把所有要消耗时间的情况列举出来。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxN=100000+10,N=100+5;
int n,cnt;
bool b[N];//true==down false==up
char ch[maxN];
//rbw
int main(){
cin>>n;
cin>>ch;
b[1]=true;
b[2]=true;
b[3]=true;
for(int i=0;i<n;i++){
if(ch[i]=='W'){
if(b[3]==false){
cnt++;
b[3]=true;
}
//cout<<cnt<<endl;
continue;
}else if(ch[i]=='B'){
if(b[3]==true){
cnt++;
b[3]=false;
}
if(b[2]==false){
cnt++;
b[2]=true;
}
//cout<<cnt<<endl;
continue;
}else if(ch[i]=='R'){
if(b[3]==true){
cnt++;
//cout<<"==="<<endl;
b[3]=false;
}
if(b[2]==true){
cnt++;
//cout<<"===="<<endl;
b[2]=false;
}
if(b[1]==false){
cnt++;
//cout<<"======"<<endl;
b[1]=true;
}
//cout<<cnt<<endl;
continue;
}
}
cout<<cnt;
return 0;
}