蓝桥杯-01小游戏

简单的模拟关键在于怎么降低时间复杂度

20%(for循环时间复杂度高)

复制代码
#include <iostream>
using namespace std;
int main()
{
  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  int t,t1;
  while(q--)
  {
  	cin>>t;
    if(t==1)
      cout << s.find('1')+1 << endl;
  	else
  		{
		  cin>>t1;
		  if(s[t1-1]=='0')
		  s[t1-1]='1';
		  else
		  s[t1-1]='0';
		}
    }
  return 0;
}

100%

复制代码
#include <iostream>
using namespace std;
int main()
{
  int n,t;
  cin >> n >> t;
  string s;
  cin >> s;
  while(t--){
    int a;
    cin >> a;
    if(a==1){
      cout << s.find('1')+1 << endl;
    }else{
      int b;
      cin >> b;
      if(s[b-1]=='1')
        s[b-1]='0';
      else
        s[b-1]='1';
    }
  }
  return 0;
}
相关推荐
h39741 小时前
DirectShow过滤器开发-视频源过滤器
c++·windows·音视频·directshow
程序猿编码3 小时前
榨干 RTX5090 算力!Qwen3 专用单卡推理引擎,手写C++/CUDA 算子实现 MTP 推测解码
开发语言·c++·大模型推理·qwen3·多模态推理
西飘客3 小时前
vs 怎么根据dll 生成lib文件
c++·qt
程序员老陆4 小时前
深入理解 C++ thread_local:线程私有存储的正确打开方式
开发语言·c++·程序设计
信奥卷王5 小时前
[GESP202609 六级] 分树规划
算法
夏幻灵5 小时前
LeetCode 21:合并两个有序链表——双指针与哑节点详解
算法·leetcode·链表
徐小黑ACG6 小时前
Golang 基础05 结构体struct
开发语言·算法·golang
Navigator_Z7 小时前
LeetCode //C - 1286. Iterator for Combination
c语言·算法·leetcode
北极有牛7 小时前
cpp学习笔记--常量指针
java·开发语言·算法