题意:给定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. JAVA语言实现简单登录界面

    程序设计思想: 使用Math.random()方法循环生成6个97~122之间的随机整数(对应ASCII码值‘a’~‘z’),将其转化为char型变量,连接成为一个6位字符串作为验证码输出,提示用户输 ...

  2. Jmeter-maven-plugin github 版本插件变更历史

    https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/blob/master/CHANGELOG.md

  3. day04-MyBatis的注解开发

    单表的CRUD注解开发: User实体类: package com.zyb.pojo; import java.io.Serializable; import java.util.Date; publ ...

  4. 某元素 fixed 后,从页面消失

    position: fixed; top: 0; left: 0; width: 100%; z-index: 1; 一开始是定位后,元素就从页面消失了,添加了 层级 之后就可以了.

  5. 国外电商网站snapdeal爬取流程

    首页爬取 1.首页获取各个目录的url 如所有优惠all_offers的其中urlhttps://www.snapdeal.com/products/men-apparel-shirts?sort=p ...

  6. 每个 JavaScript 开发者都该懂的 Unicode

    英文原文标题:what-every-javascript-developer-should-know-about-unicode (译者注:本文含有Unicode辅助平面的特殊字符,部分浏览器可能无法 ...

  7. 数据包报文格式(IP包、TCP报头、UDP报头)

    转自: https://blog.51cto.com/lyhbwwk/2162568 一.IP包格式 IP数据包是一种可变长分组,它由首部和数据负载两部分组成.首部长度一般为20-60字节(Byte) ...

  8. HDU 5568:sequence2 大数+DP

    sequence2  Accepts: 93  Submissions: 358  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 6553 ...

  9. CentOS初始化脚本(未完)

    #!/bin/bash release=`` .shutdown selinux [ -e "/etc/selinux/config" ] && sed -i 's ...

  10. Ubuntu18.04下Qt5.9.8连接mysql数据库失败的解决办法

    问题: 连接mysql数据库时,出现如下 提示: QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQ ...