zoukankan      html  css  js  c++  java
  • C. Adding Powers

    题目链接:https://codeforces.com/contest/1312/problem/C

    想法:

    读题之后就会发现其实就是把一个数转化成 k 进制并且 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;
    }
  • 相关阅读:
    个人作业8 单词统计
    个人作业7 第一阶段SCRUM冲刺(八)
    大二暑假周总结(二)
    大二暑假周总结(一)
    梦断代码-阅读笔记03
    个人课程总结
    梦断代码-阅读笔记02
    大二下周总结(16)
    梦断代码-阅读笔记01
    最长英语单词链
  • 原文地址:https://www.cnblogs.com/-Ackerman/p/12585010.html
Copyright © 2011-2022 走看看