丶丶丨┐一丶丶丶乀ㄑㄑ丶丨一一丨┐一

· · 个人记录

总结

传送门

T1:请比较数字比较数字

{\color{red}{50}}{\color{green}{tps}}

错误代码:

#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
  cin >> s;
  for(int i = 0;i<s.size();i++){
    if(s[i]=='0')cout << 1;
    else cout << s[i];
  }
  return 0;
}

错误原因:

$2.$考虑不完全 ~~3.样例误导~~ --- 正确代码: ```cpp #include<bits/stdc++.h>//万能头 using namespace std; string s;//输入的数(用整形会WA) bool f;//判断是否输出1 int main(){//主函数 cin >> s;//输入这个数 for(int i = 0;i<s.size();i++){//遍历 if(f==1) cout << 1;//如果标记就输出1 else {//否则判断 if(s[i]=='0'){f=1;cout << 1;}//如果是0 else cout << s[i];//否则 } } return 0; } `````` T2:~~弓的弓~~张的弓 ${\color{gray}{未交}}

正确代码:

#include<bits/stdc++.h>
using namespace std;
long long t;//数据数量
int main(){
    cin >> t;//输入
    while(t--){
        long long n,m,k;
        cin >> n >> m >> k;//长\宽\步数
        long long x,y;//坐标
        y=k/n+1;//通过公式(步数/长得到的高,+1是为了防止y=0的情况,因为是从1开始)确定y
        if(y%2==1)x=k%n+1;//如果y是奇数(将x赋值为步数%长得到在这一行从起点到x的长度,因为是从1开始,所以要+1)
        else x=n-k%n;//否则(将x赋值为长-步数%长是从反方向计数,由于从1开始,+1和-1会抵消)
        cout << abs(x-1)+abs(y-1) << endl;//通过公式(因为输出时要从0开始,所以要-1,同时为了防止负数要取绝对值,并按照曼巴顿距离输出)输出
    }
    return 0;
}

T3:可可很高兴。 可可口乐

{\color{green}{AC}}

正确代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
string s;//盗版可乐的名字
struct node{//bfs结构体
    string x;//状态
    int step;//步数
};
void f(){//bfs
    queue<node> q;//bfs队列
    q.push({s,0});//入队
    while(q.size()){//开始bfs
        node p = q.front();//取队首
        if(p.x=="cocacola"){//判断是不是CocaCola
            cout << p.step;//输出
            return ;//完成bfs
        }//遍历两个不重复的元素并交换进行BFS
        for(int i = 0;i<8;i++){
            for(int j = 0;j<8;j++){
                if(i==j) continue;//纺织i==j
                string ss=p.x;//复制一个p.x
                swap(ss[i],ss[j]);//按题意交换
                q.push({ss,p.step+1});//入队
            }
        }
        q.pop();//出队防TLE
    }
}
int main(){
    cin >> s;//输入
    f();//bfs
    return 0;
}

T4.小萌的警卫梦的守卫

{\color{gray}{未交}}

正确代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[10000007],s[10000007],b[10000007],rs[10000007],n,q,t;//体力值\体力值前缀和\倒过来的体力值\倒过来的体力值的前缀和
signed main(){//主函数
    cin >> n >> q;//输入
    for(int i = 1;i<=n;i++){
        cin >> a[i];
        b[n-i+1]=a[i];//录入b
        s[i]=a[i]+s[i-1];//a的前缀和
    }
    for(int i = 1;i<=n;i++){//b的前缀和
        rs[i]=b[i]+rs[i-1];
    }

    while(q--){//q次查询
        cin >> t;//输入
        int l = upper_bound(s+1,s+1+n,t)-s-1;//二分查找在s中最小>t的值
        int r = upper_bound(rs+1,rs+1+n,t)-rs-1;//二分查找在rs中最小>t的值
        if(l+r>n) cout << "Zombies ate your brain!" << endl;//如果l+r>n
        else cout << n-(l+r)<<  endl;//否则
    }
    return 0;
}