【LGR-148-Div.3】洛谷基础赛 #1 & MGOI Round I

【LGR-148-Div.3】洛谷基础赛 #1 & MGOI Round I

P9502 『MGOI』Simple Round I | A. 魔法数字

思路

通过题目信息,可以很容易想出用暴力枚举的方式一个个去枚举这个整数m,当发现2m>=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;
}



P9504 魔法禁林

P9505 『MGOI』Simple Round I | D. 魔法环

posted @   IFREAD  阅读(102)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示