Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
57517 Ender S2 C++ 编译错误 0 0 MS 0 KB 1100 2022-10-04 11:33:08

Tests(0/0):


#include <iostream> #include <map> #include <queue> using namespace std; struct Node { long long x,stp; }; map<long long,long long>p; int d,l,s; inline long long abs(long long x) { if(x < 0) return -x; return x; } void BFS(int x) { queue<Node>q; p.clear(); q.push((Node){1,0}); while(!q.empty()) { Node ak = q.front(); q.pop(); if(ak.x == x) { s = ak.stp; break; } if(!p[ak.x<<1]) { p[ak.x<<1] = ak.x; q.push((Node){ak.x<<1,ak.stp + 1}); } if(ak.x % 3 == 1) { if(!p[ak.x / 3]) { p[ak.x / 3] = ak.x; q.push((Node){ak.x / 3,ak.stp + 1}); } } if(min(abs(ak.x),abs(ak.x - d)) <= l&&!p[ak.x - d]) { p[ak.x - d] = ak.x; q.push((Node){ak.x - d,ak.stp + 1}); } } } void Path(int x) { if(x == 1) { cout<<1<<' '; return; } Path(p[x]); cout<<x<<' '; return; } int main() { int T; cin>>T>>d>>l; while(T--) { int x; cin>>x; BFS(x); cout<<s<<' '; Path(x); cout<<endl; } return 0; }


测评信息: