题意:给你n个数和一个底数k,每个数每次能减去k^i(i=0,1,2,....),每个k^i只能用一次,问是否能够将每个数变为0.

题解:我们将每个数转化为k进制,因为每个k^i只能用一次,所以我们统计每个位置上的cnt,若cnt>1,则需要多次用到k^i,则不满足条件.

代码:

 1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <stack>
7 #include <queue>
8 #include <vector>
9 #include <map>
10 #include <set>
11 #include <unordered_set>
12 #include <unordered_map>
13 #define ll long long
14 #define fi first
15 #define se second
16 #define pb push_back
17 #define me memset
18 const int N = 1e6 + 10;
19 const int mod = 1e9 + 7;
20 using namespace std;
21 typedef pair<int,int> PII;
22 typedef pair<long,long> PLL;
23
24 int t;
25 int n,k;
26 ll a[N];
27 int cnt[N];
28
29 bool check(){
30 me(cnt,0,sizeof(cnt));
31 for(int i=0;i<n;++i){
32 int pos=0;
33 while(a[i]){
34 cnt[pos]+=a[i]%k;
35 a[i]/=k;
36 pos++;
37 }
38 }
39 for(int i=0;i<=60;++i){
40 if(cnt[i]>1) return false;
41 }
42 return true;
43 }
44
45 int main() {
46 ios::sync_with_stdio(false);
47 cin>>t;
48 while(t--){
49 cin>>n>>k;
50 for(int i=0;i<n;++i) cin>>a[i];
51 if(check()) puts("YES");
52 else puts("NO");
53 }
54
55
56
57 return 0;
58 }

Codeforces ECR 83 C. Adding Powers (位运算)的更多相关文章

  1. Codeforces Round #443 (Div. 2) C 位运算

    C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  2. Codeforces F. Bits And Pieces(位运算)

    传送门. 位运算的比较基本的题. 考虑枚举\(i\),然后二进制位从大到小考虑, 对于第\(w\)位,如果\(a[i][w]=1\),那么对\(j.k\)并没有什么限制. 如果\(a[i][w]=0\ ...

  3. codeforces 245 D. Restoring Table(位运算+思维)

    题目链接:http://codeforces.com/contest/245/problem/D 题意:给出一个矩阵b,b[i][j]=a[i]&a[j],b[i][i]=-1.然后求a[i] ...

  4. Codeforces 734F Anton and School(位运算)

    [题目链接] http://codeforces.com/problemset/problem/734/F [题目大意] 给出数列b和数列c,求数列a,如果不存在则输出-1 [题解] 我们发现: bi ...

  5. CodeForces 558C Amr and Chemistry (位运算,数论,规律,枚举)

    Codeforces 558C 题意:给n个数字,对每一个数字能够进行两种操作:num*2与num/2(向下取整),求:让n个数相等最少须要操作多少次. 分析: 计算每一个数的二进制公共前缀. 枚举法 ...

  6. Codeforces 868D Huge Strings - 位运算 - 暴力

    You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...

  7. 图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest

    题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...

  8. Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

    & -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...

  9. Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400

    题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 ...

随机推荐

  1. 【Python】国内pip节点

    pip在国内使用国内节点: http://pypi.douban.com/simple 现在已经无法使用了,新版的python3需要使用https://pypi.douban.com/simple/ ...

  2. 【Linux】将ens33修改为eth0 网卡方法

    1.编辑 grub 配置文件 vim /etc/sysconfig/grub # 其实是/etc/default/grub的软连接 # 为GRUB_CMDLINE_LINUX变量增加2个参数,添加的内 ...

  3. Arduino—学习笔记—基础语法

    图解 函数具体讲解 pinMode(工作接脚,模式) 工作接脚 工作接脚编号(0--13与A0--A5) 模式 工作模式:INPUT或OUTPUT 例子 将8接口设置为输出模式 pinMode(8,O ...

  4. rename命令和批量重命名

    本文为转载文章,转发自 https://blog.csdn.net/GGxiaobai/article/details/53507454 早期版本的rename是C语言版本,如今新的Ubuntu中采用 ...

  5. 误删除SAP ECC中的profile文件

    环境:ECC6.0 EHP4  FOR ORACLE ON WINDWS X64下 今天在RZ10配置系统参数文件的时候,不小心错删除了instance profile文件,这下惨了,这是操作系统层级 ...

  6. Sklearn 与 TensorFlow 机器学习实战—一个完整的机器学习项目

    本章中,你会假装作为被一家地产公司刚刚雇佣的数据科学家,完整地学习一个案例项目.下面是主要步骤: 项目概述. 获取数据. 发现并可视化数据,发现规律. 为机器学习算法准备数据. 选择模型,进行训练. ...

  7. 阿里云OSS对象存储服务(二)

    一.使用SDK 在OSS的概览页右下角找到"Bucket管理",点击"OSS学习路径" 点击"Java SDK"进入SDK开发文档 二.创建 ...

  8. mysql 设置外键约束时如何删除数据

    Mysql中如果表和表之间建立的外键约束,则无法删除表及修改表结构 解决方法是在Mysql中取消外键约束: SET FOREIGN_KEY_CHECKS=0; 然后将原来表的数据导出到sql语句,重新 ...

  9. nothreading use single threaded

    threading:   # ThreadingMixIn.daemon_threads indicates how threads will behave on an   # abrupt shut ...

  10. How to Gracefully Close Channels

    小结: 1. When a goroutine sends a value to a channel, we can view the goroutine releases the ownership ...