C. Adding Powers
程序员文章站
2024-03-17 14:30:52
...
位运算.一开始没什么思路,参考了下别人的做法.
链接: https://www.cnblogs.com/LH2000/p/12455934.html.
附ac代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(int argc, char const *argv[])
{
ll t;
cin >> t;
//一开始数组开小了
ll a[100], note[105];
while(t--)
{
ll n, k;
cin >> n >> k;
memset(a, 0, sizeof(a));
memset(note, 0, sizeof(note));
for (int i = 0; i < n; ++i)
{
cin >> a[i];
ll j = 0;
while(a[i])
{
note[j] += a[i] % k;
a[i] /= k;
j++;
}
}
bool flag = true;
for (int k = 0; k < 70; ++k)
{
if (note[k] > 1)
{
flag = false;
break;
}
}
if (flag) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}