B. Divisiblity of Differences
B. Divisiblity of Differences
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
Input
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.
Output
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.
如果集合中两两之差能被m整除,那么它们%m之后的余数应该相等。
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar()
//by war
//2017.11.1
using namespace std;
int n,k,m;
int a[];
int b[];
int l;
int cnt; void in(int &x)
{
int y=;
char c=g();x=;
while(c<''||c>'')
{
if(c=='-')
y=-;
c=g();
}
while(c<=''&&c>='')x=(x<<)+(x<<)+c-'',c=g();
x*=y;
}
void o(int x)
{
if(x<)
{
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main()
{
in(n),in(k),in(m);
For(i,,n)
{
in(a[i]);
b[a[i]%m]++;
if(cnt<b[a[i]%m])
{
cnt=b[a[i]%m];
l=a[i]%m;
}
}
if(cnt<k)
{
puts("No");
exit();
}
puts("Yes");
For(i,,n)
{
if(a[i]%m==l)
{
k--;
o(a[i]),p(' ');
}
if(k==)
break;
}
return ;
}
B. Divisiblity of Differences的更多相关文章
- Codeforces B. Divisiblity of Differences
B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input ...
- codeforces #441 B Divisiblity of Differences【数学/hash】
B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input ...
- Codeforces 876B:Divisiblity of Differences(数学)
B. Divisiblity of Differences You are given a multiset of n integers. You should select exactly k of ...
- 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. 思路: 差能 ...
- Codeforces 876B Divisiblity of Differences:数学【任意两数之差为k的倍数】
题目链接:http://codeforces.com/contest/876/problem/B 题意: 给你n个数a[i],让你找出一个大小为k的集合,使得集合中的数两两之差为m的倍数. 若有多解, ...
- CodeForces - 876B Divisiblity of Differences
题意:给定n个数,从中选取k个数,使得任意两个数之差能被m整除,若能选出k个数,则输出,否则输出“No”. 分析: 1.若k个数之差都能被m整除,那么他们两两之间相差的是m的倍数,即他们对m取余的余数 ...
- 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, ...
- Codeforces Round #441 (Div. 2)【A、B、C、D】
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...
- Codeforces Round #441 (Div. 2)
Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...
随机推荐
- Linux下的启动oracle的EM的命令
Linux下的启动oracle的EM的命令 1.启动数据库 su - oracle $sqlplus / as sysdba sql>startup 2.启动监听 $lsnrctl LSNRCT ...
- 修改 sql 提示符信息:
Last login: Thu Dec 8 19:18:08 2016 from 192.168.242.1 [root@localhost ~]# su - oracle [oracle@local ...
- Confluence 6 垃圾收集性能问题
这个文章与 Oracle 的 Hotspot JVM 虚拟机的内存管理为参照的.这些建议是我们在对大的 Confluence 安装实例用户进行咨询服务的时候得到的最佳配置方案. 请不要在 Conflu ...
- Deal with Warning: mysqli::__construct(): (HY000/2002)
1.安装XAMPP之后,如果之前安装过MySQL或者 apache,启动XAMPP中的响应的服务的时候回出现报错, 出错的原因,具体看报错的原因,如果是端口占用,在配置中修改端口号,如果是提示 “Fo ...
- 性能测试四十六:Linux 从网卡模拟延时和丢包的实现
Linux 中模拟延时和丢包的实现 使用ifconfig命令查看网卡 Linux 中使用 tc 进行流量管理.具体命令的使用参考 tc 的 man 手册,这里简单记录一下使用 tc 模拟延时和丢包的命 ...
- Python获取当前时间及时间转换(datetime)
datetime是Python处理日期和时间的标准库 获取当前时间 import datetime day = datetime.datetime.now() day2 = datetime.date ...
- Vue注意事项及用得较多的属性归纳
1.prop是一个对象而不是字符串数组时,它包含验证要求.props: { // 基础类型检测 (`null` 意思是任何类型都可以) propA: Number, // 多种类型 propB: [S ...
- python 全栈开发,Day71(模型层-单表操作)
昨日内容回顾 1. {% include '' %} 2. extend base.html: <html> ..... ..... ..... {% block content%} {% ...
- 重新认识python
为什么这样说呢,我几个月前就开始学python,但是一直都没有进步,还就只是会一些其它语言的共性的问题,也就是新学习的约等于0. 后来一直找一些适合自己的教材,通过同学找到了一个学长的教程. 开始了新 ...
- Just Oj 2017C语言程序设计竞赛高级组A: 求近似值(矩阵快速幂)
A: 求近似值 时间限制: 1 s 内存限制: 128 MB 提交 我的状态 题目描述 求⌊(5–√+6–√)2n⌋⌊(5+6)2n⌋%9932017. 例如:n=1,(5–√+6–√)2( ...