听灌多,求助
  • 板块灌水区
  • 楼主Quartz_Blocks
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/6/24 21:55
  • 上次更新2024/6/25 11:38:59
查看原帖
听灌多,求助
1059176
Quartz_Blocks楼主2024/6/24 21:55

题

WA   on   T5\color{red}WA \,\,\, on \,\,\,T5

#include <bits/stdc++.h>
using namespace std;
int k,n;
bool used[1000010];
struct node{
    int n,step;
};

int main(){
	cin >> k >> n;
    if(n == k){
        cout << 0;
        return 0;
    }
    queue <node> q;
    memset(used,0,sizeof(used));
    q.push(node{k,0});
    used[k] = 1;
    while(!q.empty()){
        node u = q.front();
        q.pop();
        for(int i = 1;i <= 1;i++){
            node v = u;
            v.step++;
            v.n--;
            
            if(used[v.n]) continue;
            if(v.n == n){
                cout << v.step << endl;
                return 0;
            }
            //cout << v.n << endl;
            q.push(v);
            used[v.n] = 1;
        }
        for(int i = 1;i <= 1;i++){
            node v = u;
            v.step++;
            v.n++;
            
            if(used[v.n]) continue;
            if(v.n == n){
                cout << v.step << endl;
                return 0;
            }
            //cout << v.n << endl;
            q.push(v);
            used[v.n] = 1;
        }
        for(int i = 1;i <= 1;i++){
            node v = u;
            v.step++;
            v.n -= 5;
            if(used[v.n]) continue;
            if(v.n == n){
                cout << v.step << endl;
                return 0;
            }
            //cout << v.n << endl;
            q.push(v);
            used[v.n] = 1;
        }
        for(int i = 1;i <= 1;i++){
            node v = u;
            v.step++;
            v.n+= 5;
            if(used[v.n]) continue;
            if(v.n == n){
                cout << v.step << endl;
                return 0;
            }
            //cout << v.n << endl;
            q.push(v);
            used[v.n] = 1;
        }
        for(int i = 1;i <= 1;i++){
            node v = u;
            v.step++;
            v.n+=10;
            
            if(used[v.n]) continue;
            if(v.n == n){
                cout << v.step << endl;
                return 0;
            }
            //cout << v.n << endl;
            q.push(v);
            used[v.n] = 1;
        }
        for(int i = 1;i <= 1;i++){
            node v = u;
            v.step++;
            v.n-=10;
            
            if(used[v.n]) continue;
            if(v.n == n){
                cout << v.step << endl;
                return 0;
            }
            //cout << v.n << endl;
            q.push(v);
            used[v.n] = 1;
        }
    }
cout << endl;
	return 0;
}
2024/6/24 21:55
加载中...