提交时间:2022-10-04 11:25:52
运行 ID: 57458
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<math.h> using namespace std; const int N = 1505; long long step[N]; int main() { int d , l , q; cin >> q >> d >> l; while(q--) { long long n; cin >> n; int idx = 0; while(n < 0 && abs(n) >= 1) { step[idx++] = n; if(n % 2 == 0) n /= 2; else if(abs(n) <= l) n += d; else if(n % 2 == -1) n *= 3 , n++; } if(n == 0) { step[idx++] = 0; } else while(n != 1) { step[idx++] = n; if(n % 2 == 1) n *= 3 , n++; else n /= 2; } printf("%d 1 " , idx); for(int i = idx - 1 ; i >= 0 ; i--) i == 0 ? printf("%d\n" , step[i]) : printf("%d " , step[i]); } return 0; }