题意:给定n个数,从中选取k个数,使得任意两个数之差能被m整除,若能选出k个数,则输出,否则输出“No”。

分析:

1、若k个数之差都能被m整除,那么他们两两之间相差的是m的倍数,即他们对m取余的余数是相同的。

2、记录n个数对m取余的余数,计算出数量最多的余数ma。

3、ma>=k,才能选出,并输出即可。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int a[MAXN];
int yu[MAXN];
map<int, int> mp;
int main(){
int n, k, m;
scanf("%d%d%d", &n, &k, &m);
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
}
for(int i = 0; i < n; ++i){
yu[i] = a[i] % m;
++mp[yu[i]];
}
int ma = 0;
int id = 0;
for(map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it){
if((*it).second > ma){
ma = (*it).second;
id = (*it).first;
}
}
if(ma < k){
printf("No\n");
}
else{
printf("Yes\n");
bool flag = true;
int t = 0;
for(int i = 0; i < n; ++i){
if(yu[i] == id){
if(flag) flag = false;
else printf(" ");
printf("%d", a[i]);
++t;
if(t == k) break;
}
}
printf("\n");
}
return 0;
}

  

CodeForces - 876B Divisiblity of Differences的更多相关文章

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

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

  2. Codeforces B. Divisiblity of Differences

    B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input ...

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

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

  4. codeforces #441 B Divisiblity of Differences【数学/hash】

    B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input ...

  5. B. Divisiblity of Differences

    B. Divisiblity of Differencestime limit per test1 secondmemory limit per test512 megabytesinputstand ...

  6. codeforces 876B

    B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input ...

  7. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) B. Divisiblity of Differences

    http://codeforces.com/contest/876/problem/B 题意: 给出n个数,要求从里面选出k个数使得这k个数中任意两个的差能够被m整除,若不能则输出no. 思路: 差能 ...

  8. CodeForces - 876B H - 差异的可分割性

    现在有n个整数,在这n个数中找出k个数,保证这k个数中任意两个数差的绝对值可以被m整除. Input第一行输入三个整数n,k,m(2<=k<=n<=100000,1<=m< ...

  9. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)

    A. Trip For Meal 题目链接:http://codeforces.com/contest/876/problem/A 题目意思:现在三个点1,2,3,1-2的路程是a,1-3的路程是b, ...

随机推荐

  1. mcast_block_source函数

    #include <errno.h> #include <sys/socket.h> #define SA struct sockaddr int mcast_block_so ...

  2. python requirements.txt批量下载安装离线

    有些情况下我们需要下载N个第三方包,或者下载的包依赖其它包,一个个下载非常浪费时间.这时我们可以通过如下两种方式的命令批量下载. 方式1 pip download -d /tmp/packagesdi ...

  3. Linux - 监控工具Conky

    主题Harmattan,https://www.jianshu.com/p/5c8d4a1f4c91,这个主题在deepin linux下有黑框背景,因为是伪透明,所以选择黑色背景的主题即可

  4. 【转载】 NVIDIA Tesla/Quadro和GeForce GPU比较

    原文地址: https://blog.csdn.net/m0_37462765/article/details/74394932 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议 ...

  5. electron 查看版本信息

    console.log(process) console.log(process.versions.electron) process 里包含很多信息:

  6. Python学习笔记002

    字符编码:把二进制字符翻译成字符 ASCII码表    256    一个字节,8个比特 支持中文: GB2312 GBK1.0 GB18030 BIG5(台湾) unicode UTF-8 开头定义 ...

  7. linux 部署java 项目命令

    1:服务器部署路径:/home/tomcat/tomcat/webapps  (用FTP工具链接服务器把包上传到此目录) 2:进入项目文件夹 cd /home/tomcat/tomcat/webapp ...

  8. awk及sum求和!

    awk 也是一个强大的编辑工具,它比 sed 的功能更加强大,可以在无交互的情况下实现相当复杂的文本操作. 1.awk 的语法 awk [选项] ' print $1' 文件名 选项 -F指定分隔符 ...

  9. Day11 - N - Game HDU - 3389

    题目链接 题意是说有1到n个标号的盒子,选择一个非空的盒子A,B是否空无所谓,满足(A+B)%2=1,(A+B)%3=0,A>B 解上面的同余方程组,最小解为3,循环为2*3=6,那我们可以把前 ...

  10. 设计模式课程 设计模式精讲 7-3 建造者模式源码解析(jdk+guava+spring+mybaties)

    1 源码解析 1.1 jdk解析 1.2 guava解析 1.3 spring解析 1.4 mybaties解析 1 源码解析 1.1 jdk解析 String public StringBuilde ...