C. Adding Powers

位运算.一开始没什么思路,参考了下别人的做法.
链接: 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;
}
发布了7 篇原创文章 · 获赞 0 · 访问量 79

猜你喜欢

转载自blog.csdn.net/qq_41854014/article/details/104879769