题解:CF1505D Xenolith? Hippodrome?
本题的题面十分简单,但是我们可以从数据范围中与样例中看出一些细节信息。
首先是 $1 \le N \le 1024,2 \le M \le 16$,从 $M$ 的数据范围中很容易联想到 $N$ 在 $M$ 进制下所表示的数。把样例中的数字进行转换,分别得到 $(2)_3,(11)_2,(21)_{16},(11)_5$。其中答案分别分别为 $\texttt{YES,NO,YES,NO}$,因此大胆猜测根据是否有重复数字来判断(不得不说这需要很大的脑洞)。
因此最后有完整代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #define init(x) memset (x,0,sizeof (x)) #define ll long long #define ull unsigned long long #define INF 0x3f3f3f3f using namespace std; const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; inline int read (); bool re[20]; int main () { int a = read (),b = read (); while (a != 0) { if (re[a % b]) { puts ("NO"); return 0; } re[a % b] = 1; a /= b; } puts ("YES"); return 0; } inline int read () { int s = 0;int f = 1; char ch = getchar (); while ((ch < '0' || ch > '9') && ch != EOF) { if (ch == '-') f = -1; ch = getchar (); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar (); } return s * f; }
|