题意:给你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. oracle坚决不挂01(表,索引,视图的创建,修改,删除,查询)

    考试快来了,来篇oracle干货,复习一下(挣扎一下) 废话不多说,开始写! 这篇是数据库对象的有关操作的总结! 数据库对象有熟悉的表,视图,索引,序列,同义词等(这个oracle东西真不少,小声bb ...

  2. 【Linux】history用法

    通过history命令可以查看我们在系统中输入过的命令 history命令的一些常用参数 -c  清空内存中命令历史 -d #  删除指定的历史命令,比如 history -d 100 ,就是删除第1 ...

  3. SDUST数据结构 - chap2 线性表

    一.判断题: 二.选择题: 三.编程题: 7-1 jmu-ds-顺序表区间元素删除 : 输入样例: 10 5 1 9 10 67 12 8 33 6 2 3 10 输出样例: 1 67 12 33 2 ...

  4. EXPORT和IMPORT使用示例

    1 report ztestprog. 2 data:begin of itab1 occurs 0, 3 ff(10), 4 end of itab1. 5 data:itab2 like itab ...

  5. 入门OJ:售货员的难题

    题目描述 某乡有n个村庄(1<n<15),有一个售货员,他要到各个村庄去售货,各村庄之间的路程s(0<s<1000)是已知的,且A村到B村与B村到A村的路大多不同.为了提高效率 ...

  6. Python爬虫:数据分析小能手:JSON库的用法

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,易于人阅读和编写. 给大家推荐一个Python交流的q裙,大家在学习遇到了什么问题都可以进群一起交流,大家 ...

  7. OpenStack各组件的常用命令

    openstack命令 openstack-service restart    #重启openstack服务 openstack endpoint-list        #查看openstack的 ...

  8. 对于Spring MVC 拦截器的一些了解

    Spring MVC 拦截器的执行顺序 应用场景 假设请求 localhost:8080/ 则要求直接重定向到 localhost:8080/login ; 定义拦截器顺序 permission lo ...

  9. 任何Python线程执行前,必须先获得GIL锁,然后,每执行100条字节码,解释器就自动释放GIL锁,让别的线程有机会执行

    任何Python线程执行前,必须先获得GIL锁,然后,每执行100条字节码,解释器就自动释放GIL锁,让别的线程有机会执行 多线程 - 廖雪峰的官方网站 https://www.liaoxuefeng ...

  10. 【转载】【Python模块】datetime

    原文地址 一.datetime模块介绍 (一).datetime模块中包含如下类: 类名 功能说明 date 日期对象,常用的属性有year, month, day time 时间对象 datetim ...