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\)个点的 ...
随机推荐
- Centos7 设置静态IP地址
一: 修改网卡配置文件(操作前先备份一下该文件),/etc/sysconfig/network-scripts/ 具体操作如下: 1:进入修改目录 [root@localhost ~]# clear ...
- 使用 mod_rewrite 来修改 Confluence 6 的 URLs
备注:这个页面的文档是 Apache 的配置,而不是 Confluence 自己的配置.Atlassian 将会对 Confluence 的配置提供支持,但是我们不能保证能够对你所有在配置 Apach ...
- vue 中axios 的基本配置和基本概念
axios的基本概念及安装配置方法 ajax:异步请求,是一种无需再重新加载整个网页的情况下,能够更新部分网页的技术 axios:用于浏览器和node.js的基于promise的HTTP客户端 a ...
- vue element-UI 升级报错Cannot find module "element-ui/lib/theme-default/index.css"
饿了么 用之前的版本 有些组件跟api 不一样了所以更新了最新的版本,发现 报一堆错误 主要错误是这个 Cannot find module "element-ui/lib/theme-de ...
- SpringCloud简介
1.什么是微服务? 微服务就是不同的模块部署在不同的服务器上面,通过接口去访问就是微服务 作用:利用分布式解决网站高并发带来的问题 2.什么是集群? 多台服务器部署相同应用构成一个集群 作用:通过负载 ...
- laravel 分类的列表查询
public function index(Request $request, ResponseFactoryContract $response, QuestionModel $questionMo ...
- 古代猪文:数论大集合:欧拉定理,exgcd,china,逆元,Lucas定理应用
/* 古代猪文:Lucas定理+中国剩余定理 999911658=2*3*4679*35617 Lucas定理:(m,n)=(sp,tp)(r,q) %p 中国剩余定理:x=sum{si*Mi*ti} ...
- bzoj 1076
发现自己已经把期望dp忘光了... 其实本质上非常简单,就是利用状压的思想跑期望 首先很容易设计出状态:记状态f[s][i]表示到了第i个点,之前已选过的点的状态为s时所能获得的最大期望得分 但是会发 ...
- vue 的动画
1.vue 的动画流程分为enter,和leave分别对应以下两幅图 <!doctype html><html lang="en"><head> ...
- Vue 导入文件import、路径@和.的区别
***import: html文件中,通过script标签引入js文件.而vue中,通过import xxx from xxx路径的方式导入文件,不光可以导入js文件. from前的:“xxx”指的是 ...