CF1312C Adding Powers
作者:互联网
题目链接:https://codeforces.com/contest/1312
题目大意:
能否对一个数组执行任意次操作,使得其变为目标数组。
对于第i次操作,我们可以放弃,或给数组中任意一个元素加上k^i
想法:
我们不难发现一个数 = k^x + k^y + k^z + ... (x != y != z)
这个形式很像我们的二进制所以我们可以知道就是把这个数转化为 k 进制,然后每一位只可以用一次
#pragma GCC optimize(3,"Ofast","inline")//O3优化 #pragma GCC optimize(2)//O2优化 #include <algorithm> #include <string> #include <string.h> #include <vector> #include <map> #include <stack> #include <set> #include <queue> #include <math.h> #include <cstdio> #include <iomanip> #include <time.h> #include <bitset> #include <cmath> #include <sstream> #include <iostream> #include <cstring> #define LL long long #define ls nod<<1 #define rs (nod<<1)+1 #define pii pair<int,int> #define mp make_pair #define pb push_back #define INF 0x3f3f3f3f #define max(a,b) (a>b?a:b) #define min(a,b) (a<b?a:b) const double eps = 1e-10; const int maxn = 2e6 + 10; const LL mod = 1e9 + 7; int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;} using namespace std; int vis[100]; int main() { ios::sync_with_stdio(0); int T; cin >> T; while (T--) { memset(vis,0,sizeof(vis)); int n; LL k; cin >> n >> k; bool fl = false; for (int i = 1;i <= n;i++) { int cnt = 0; LL a; cin >> a; if (a == 0 || fl) continue; while (1) { if (a % k == 1) { if (!vis[cnt]) vis[cnt] = 1; else { fl = true; break; } } else if (a % k > 1) { fl = true; break; } a = a / k; cnt++; if (a == 0) break; } } if (fl) cout << "NO" << endl; else cout << "YES" << endl; } return 0; }
标签:Adding,cnt,fl,break,vis,include,Powers,CF1312C,define 来源: https://www.cnblogs.com/-Ackerman/p/12516720.html