http://codeforces.com/contest/876/problem/B

题意:

给出n个数,要求从里面选出k个数使得这k个数中任意两个的差能够被m整除,若不能则输出no。

思路:

差能够被m整除,其实就是对m取余的余数相同。那么就统计n个数的余数丢到一个map里面,最后判断是否有某个数的数量大于等于k。

代码:

 #include <stdio.h>
#include <map>
#include <vector>
using namespace std; map<int,int> mmp; int a[];
int b[]; vector<int> v; int main()
{
int n,k,m; scanf("%d%d%d",&n,&k,&m); for (int i = ;i < n;i++)
{
int t; scanf("%d",&t); b[i] = t; t %= m; a[i] = t;
} for (int i = ;i < n;i++) mmp[a[i]]++; map<int,int>::iterator it; int ans = -; for (it = mmp.begin();it != mmp.end();++it)
{
if (it -> second >= k)
{
ans = it -> first;
break;
}
} if (ans == -) printf("No\n");
else
{
printf("Yes\n"); int cnt = ; for (int i = ;i < n;i++)
{
if (b[i] % m == ans)
{
v.push_back(b[i]);
cnt++;
} if (cnt >= k) break;
} for (int i = ;i < v.size();i++)
{
printf("%d%c",v[i],i == v.size() - ? '\n' :' ');
}
} return ;
}

Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) B. Divisiblity of Differences的更多相关文章

  1. 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, ...

  2. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins

    http://codeforces.com/contest/876/problem/D 题意: 最开始有一串全部由"O"组成的字符串,现在给出n个数字,指的是每次把位置n上的&qu ...

  3. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) C. Classroom Watch

    http://codeforces.com/contest/876/problem/C 题意: 现在有一个数n,它是由一个数x加上x每一位的数字得到的,现在给出n,要求找出符合条件的每一个x. 思路: ...

  4. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A. Trip For Meal

    http://codeforces.com/contest/876/problem/A 题意: 一个人一天要吃n次蜂蜜,他有3个朋友,他第一次总是在一个固定的朋友家吃蜂蜜,如果说没有吃到n次,那么他就 ...

  5. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) E. National Property(2-sat)

    E. National Property time limit per test 1 second memory limit per test 512 megabytes input standard ...

  6. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) F. High Cry(思维 统计)

    F. High Cry time limit per test 1 second memory limit per test 512 megabytes input standard input ou ...

  7. ACM-ICPC (10/16) Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)

    A. Trip For Meal Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. ...

  8. Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) D. Labyrinth

    http://codeforces.com/contest/1064/problem/D 向上/向下加0,向左/右加1, step = 0,1,…… 求的是最少的步数,所以使用bfs. step=k ...

  9. Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) D. Labyrinth(重识搜索)

    https://codeforces.com/contest/1064/problem/D 题意 给你一个有障碍的图,限制你向左向右走的次数,问你可以到达格子的个数 思路 可以定义状态为vi[x][y ...

随机推荐

  1. 20165230 预备作业3 Linux安装及学习

    20165230 预备作业3 Linux安装及学习 安装Linux操作系统 通过学习实践基于VirtualBox虚拟机安装Ubuntu图文教程,开始了虚拟机的安装,根据教程按着步骤一步一步的完成. 遇 ...

  2. IE常见的兼容处理

    IE常见的兼容处理 1. 禁用IE兼容模式 为了保证IE能够使用最新渲染模式而不是兼容模式,在html文档头部应加入以下代码: <head> <meta charset=" ...

  3. Dubbo学习1-Hello world

    前言 互联网技术到今天已经非常成熟和稳定了,其中为了解决高并发.大规模的服务请求,出现了微服务.RPC这样的分布式架构.今天就从头开始学习RPC框架dubbo. 为什么要学Dubbo 关于分布式的解决 ...

  4. servlet实现方式(未完待续)

    servlet的是方式有三种,分别是: 1,实现servlt接口 点击查看详情 2,继承GenericServlet类[适配器模式] 3,继承HttpServlet类[模板方法设计模式]最常用的方法 ...

  5. 使用责任链模式消除if分支实践

    之前接手过一个车辆监控的工具,接受第三方推送过来的车辆状态数据然后入库.车辆状态一共有8种之多,每种状态都需要做不同 处理操作.刚接手这份代码时,针对此处处理,是庞大的if-else结构,if-els ...

  6. oracle、导出、导入

    一.数据库导入: No1.查询所有表中那些是空表. select table_name from user_tables where NUM_ROWS=0; No2.拼接字符串生成SQL执行语句. s ...

  7. 路径字符串数据转化为树型层级对象,path to json tree

    由于项目中使用了react 及 ant-design ,在使用tree树型控件时,需要 类似下面的数据, const treeData = [{ title: '0-0', key: '0-0', c ...

  8. Java源码之HashMap

    一.HashMap和Hashtable的区别 (1)HashMapl的键值(key)和值(value)可以为null,而Hashtable不可以 (2)Hashtable是线程安全类,而HashMap ...

  9. Python数据增强(data augmentation)库--Augmentor 使用介绍

    Augmentor 使用介绍 原图 random_distortion(probability, grid_height, grid_width, magnitude) 最终选择参数为 p.rando ...

  10. swift textview禁止用户使用复制粘贴

    //自定义一个TextView class Own_TextView: UITextView { override func caretRect(for position: UITextPositio ...