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\)个点的 ...
随机推荐
- Oracle存储过程中跳出循环的写法
注:本文来源于: < Oracle存储过程中跳出循环的写法 > Oracle存储过程中跳出循环的写法 记录exit和return的用法 1:exit用来跳出循环 loop IF V_ ...
- Confluence 6 配置 简易信息聚合(RSS)
一个 Confluence 的管理员可以配置下面的 RSS 特性: Confluence 针对 RSS 聚合返回的最大项目数量. Confluence 针对 RSS 聚合允许的最大时间周期. 上面两个 ...
- Confluence 6 数据导入和导出
Confluence 管理员和用户可以从各种方法向 Confluence 中导入数据.针对不同的导入方式,有关权限的要求也是不相同的.请参考页面 Import Content Into Conflu ...
- Confluence 6 编辑一个站点装饰文件
希望编辑一个站点的 decorator 文件: 进入 > 基本配置(General Configuration) > 布局(Layouts )(在Look and Feel 菜单下面) ...
- eclipse的安装及使用
1.安装 2工作区 3透视图添加透视图 关闭和显示各个子视图 点击视图右上角的关闭按钮可以关闭当前视图 可以选择Window-->Show View菜单项打开各个子视图 4创建项目 选择File ...
- Python使用正则表达式分割字符串
re.split(pattern, string, [maxsplit], [flags]) pattern:表示模式字符串,由要匹配的正则表达式转换而来. string:表示要匹配的字符串. max ...
- C++ GetModuleFileName()
关于GetModuleFileName function,参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms683197(v= ...
- MyBatis配置:在控制台打印SQL语句
1.在spring-mybatis.xml中配置语句 注意:value=”classpath:mybatis-config.xml”这个文件如果之前没有,是需要新建的 2.新建mybatis-con ...
- python---使用二叉堆实现的优先队列(列表)
哟,有实用价值 可以看到,加入是随机的,而吐出是顺序的. # coding = utf-8 # 使用二叉堆实现的优先队列(列表) class BinaryHeap: def __init__(self ...
- JavaScript数组去重的6个方法
方法一无需思考,我们可以得到 O(n^2) 复杂度的解法.定义一个变量数组 res 保存结果,遍历需要去重的数组,如果该元素已经存在在 res 中了,则说明是重复的元素,如果没有,则放入 res 中. ...