【LGR-148-Div.3】洛谷基础赛 #1 & MGOI Round I
【LGR-148-Div.3】洛谷基础赛 #1 & MGOI Round I
P9502 『MGOI』Simple Round I | A. 魔法数字
思路
通过题目信息,可以很容易想出用暴力枚举的方式一个个去枚举这个整数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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!