现在有n个整数,在这n个数中找出k个数,保证这k个数中任意两个数差的绝对值可以被m整除。

Input第一行输入三个整数n,k,m(2<=k<=n<=100000,1<=m<=100000)。 
第二行包含n个整数a1,a2,...,  an(0 <= ai <= 10^9 )。Output如果不存在这样的k个数,输出"No";
否则输出"Yes"后,在下一行输出这k个数,数与数之间用空格隔开。 (存在多种情况,输出任意一种)。Example

Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7
如果两个数对m取余得到的值相等那么二者的差值一定可以被m整除。所以余数相同的值我们把他放在一起。
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
const int N=1e5+;
vector<int >ve[N];
int main(){
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
int x;
for(int i=;i<=n;i++){
scanf("%d",&x);
int y=x%k;
ve[y].push_back(x);
} bool check=false; for(int i=;i<k;i++){
if(ve[i].size()>=m){
check=true;
puts("Yes");
for(int j=;j<m;j++){
printf("%d ",ve[i][j]);
}
break;
}
}
if(!check) puts("No");
return ;
}

CodeForces - 876B H - 差异的可分割性的更多相关文章

  1. Codeforces 1037 H. Security

    \(>Codeforces \space 1037\ H. Security<\) 题目大意 : 有一个串 \(S\) ,\(q\) 组询问,每一次给出一个询问串 \(T\) 和一个区间 ...

  2. Codeforces E. Bash Plays with Functions(积性函数DP)

    链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...

  3. Codeforces 876B Divisiblity of Differences:数学【任意两数之差为k的倍数】

    题目链接:http://codeforces.com/contest/876/problem/B 题意: 给你n个数a[i],让你找出一个大小为k的集合,使得集合中的数两两之差为m的倍数. 若有多解, ...

  4. Codeforces Gym H. Hell on the Markets 贪心

    Problem H. Hell on the MarketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vj ...

  5. iostream,iostream.h差异

    1. 不加.h的是现在C++中规定的标准,目的在于使C++代码用于移植和混合嵌入时不受扩展名.h的限制, 避免因为.h而造成的额外的处理和修改而加.h的是c语言的用法,但是在c++中也支持这种用法, ...

  6. Codeforces Gym101502 H.Eyad and Math-换底公式

    H. Eyad and Math   time limit per test 2.0 s memory limit per test 256 MB input standard input outpu ...

  7. Codeforces Gym100735 H.Words from cubes-二分图最大匹配匈牙利

    赛后补题,还是要经常回顾,以前学过的匈牙利都忘记了,“猪队友”又给我讲了一遍... 怎么感觉二分图的匈牙利算法东西好多啊,啊啊啊啊啊啊啊啊啊(吐血...) 先传送一个写的很好的博客,害怕智障找不到了. ...

  8. Codeforces 876B:Divisiblity of Differences(数学)

    B. Divisiblity of Differences You are given a multiset of n integers. You should select exactly k of ...

  9. CodeForces - 876B Divisiblity of Differences

    题意:给定n个数,从中选取k个数,使得任意两个数之差能被m整除,若能选出k个数,则输出,否则输出“No”. 分析: 1.若k个数之差都能被m整除,那么他们两两之间相差的是m的倍数,即他们对m取余的余数 ...

随机推荐

  1. IDEA报错:Could not find resource com/liwen/bean/userMapper.xml

    主要原因设idea无法识别src路径下的xml文件,要把xml文件建立在resources文件下

  2. TensorFlow v2.0的基本张量操作

    使用TensorFlow v2.0的基本张量操作 from __future__ import print_function import tensorflow as tf # 定义张量常量 a = ...

  3. Centos 8 上安装 Consul

    /* 1. 下载二进制安装文件 */下载地址:https://www.consul.io/downloads.html /* 2. 解压缩安装包 */unzip consul_1.6.2_linux_ ...

  4. [bzoj1800]fly 飞行棋<暴力>

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1800 说实话我这几天运气不错,随便在bzoj上找题都可以找到水题,这题在代码上没有丝毫难度 ...

  5. Java面试金典

    1,将构造函数声明为私有的作用 构造函数私有化,保证类以外的地方不能直接实例化该类,这种情况下,要创建这个类的实例,只能提供一个公共静态方法,像工厂方法模式,由于构造函数私有化,不能被继承. 2,在t ...

  6. MATLAB——颜色梯度显示

    一.colormap函数 figure surf(peaks) k=; mycolor=spring(k); colormap(mycolor); spring是颜色的分类.spring(k)生成k个 ...

  7. while实现2-3+4-5+6...+100 的和

    while实现2-3+4-5+6...+100 的和 可以看到规律为2-100内所有奇数都为减法,偶数为加法 设定变量 total=0: count=2 当count为偶数时与total相加,反则相减 ...

  8. Spring-Cloud-Netflix-系统架构

    目录 系统架构 概述 集中式架构 概述 特点 垂直拆分 概述 特点 系统架构分类 微服务 微服务的特点: 分布式服务: 微服务和分布式的区别: 微服务要面临的问题: springClould是什么 远 ...

  9. A. Array with Odd Sum Round #617(水题)

    A. Array with Odd Sum time limit per test 1 second memory limit per test 256 megabytes input standar ...

  10. 1020 Tree Traversals (25 分)

    Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and i ...