CodeForces - 876B Divisiblity of Differences
题意:给定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的更多相关文章
- Codeforces 876B Divisiblity of Differences:数学【任意两数之差为k的倍数】
题目链接:http://codeforces.com/contest/876/problem/B 题意: 给你n个数a[i],让你找出一个大小为k的集合,使得集合中的数两两之差为m的倍数. 若有多解, ...
- Codeforces B. Divisiblity of Differences
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 #441 B Divisiblity of Differences【数学/hash】
B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input ...
- B. Divisiblity of Differences
B. Divisiblity of Differencestime limit per test1 secondmemory limit per test512 megabytesinputstand ...
- codeforces 876B
B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input ...
- 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 H - 差异的可分割性
现在有n个整数,在这n个数中找出k个数,保证这k个数中任意两个数差的绝对值可以被m整除. Input第一行输入三个整数n,k,m(2<=k<=n<=100000,1<=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, ...
随机推荐
- linux mysql 查看数据库大小
SELECT CONCAT(TRUNCATE(SUM(data_length)//,),'MB') AS data_size, CONCAT(TRUNCATE(SUM(max_data_length) ...
- Tensorflow机器学习入门——AttributeError: module 'scipy.misc' has no attribute 'toimage'
这个bug的解决办法: import cv2 # scipy.misc.toimage(image_array).save('cifar10_data/raw/%d.jpg' % i) cv2.imw ...
- Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime
环境: ubuntu18 webstorm vue项目 报错原因: 缺少相关依赖 解决方法: npm rebuild node-sass 还未解决: npm uninstall --save node ...
- [转]Java监听器的原理与实现
原文链接 监听器是一个专门用于对其他对象身上发生的事件或状态改变进行监听和相应处理的对象,当被监视的对象发生情况时,立即采取相应的行动.监听器其实就是一个实现特定接口的普通java程序,这个程序专门用 ...
- 【转】spring IOC和AOP的理解
spring 的优点?1.降低了组件之间的耦合性 ,实现了软件各层之间的解耦 2.可以使用容易提供的众多服务,如事务管理,消息服务等 3.容器提供单例模式支持 4.容器提供了AOP技术,利用它很容易实 ...
- 吴裕雄--天生自然PythonDjangoWeb企业开发:需求
开发或者做一个项目,是要有一个需求过来的,而不是无缘无故的,启动一个项目,或者推动整个项目进行下一步迭代.这个需求可能是根据用户反馈增加的,可能是老板提出来的,也有可能是产品经理提出来的,但是无论是什 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 排版:移除默认的列表样式
<!DOCTYPE html> <html> <head> <title>菜鸟教程(runoob.com)</title> <meta ...
- Linux 下面搭建KMS服务器
1. 下载安装Linux 版的KMS服务软件 # wget https://github.com/Wind4/vlmcsd/releases/download/svn1111/binaries.tar ...
- C++中的四种类型转换运算符static_cast、dynamic_cast、const_cast和reinterpret_cast的使用
1.上一遍讲述了C语言的隐式类型转换和显示类型转换,C语言之所以增加强制类型转换,就是为了强调转换的风险性,但这种强调风险的方式是比较粗放了,粒度比较大,它并没有表明存在什么风险,风险程度如何. 2. ...
- Charles + Android 抓取Https数据包 (适用于Android 6.0及以下)
通过Charles代理,我们能很轻易的抓取手机的Http请求,因为Http属于明文传输,所以我们能直接获取到我们要抓取的内容.但是Https内容本身就是加密的,这时我们会发现内容是加密的了.本文我们来 ...