zoukankan      html  css  js  c++  java
  • Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) B. Divisiblity of Differences

    地址:

    题目:

    B. Divisiblity of Differences
    time limit per test
    1 second
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard 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 nk 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.

    Examples
    input
    3 2 3
    1 8 4
    output
    Yes
    1 4
    input
    3 3 3
    1 8 4
    output
    No
    input
    4 3 5
    2 7 7 7
    output
    Yes
    2 7 7

    思路:
      如果(a-b)%m==0 ==> a%m = b%m.
      所以判断求出每个数膜m余多少就好了。
     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 #define MP make_pair
     6 #define PB push_back
     7 typedef long long LL;
     8 typedef pair<int,int> PII;
     9 const double eps=1e-8;
    10 const double pi=acos(-1.0);
    11 const int K=1e6+7;
    12 const int mod=1e9+7;
    13 
    14 int n,m,k,a[K],cnt[K];
    15 
    16 int main(void)
    17 {
    18     cin>>n>>k>>m;
    19     for(int i=1,x;i<=n;i++)
    20         scanf("%d",a+i),cnt[a[i]%m]++;
    21     for(int i=0;i<m;i++)
    22     if(cnt[i]>=k)
    23     {
    24         printf("Yes
    ");
    25         for(int j=1,num=0;j<=n;j++)
    26         if(a[j]%m==i)
    27         {
    28             printf("%d ",a[j]);
    29             if(++num==k)
    30                 return 0;
    31         }
    32     }
    33     printf("No
    ");
    34     return 0;
    35 }
  • 相关阅读:
    WDCP控制面板的常用liunx命令集
    获取两个时间节点的月份列表&&每个月份的开始时间及结束时间
    正则表达式应用
    浏览器中的user-agent的几种模式
    Dell 服务器CentOS 6.8版本系统安装
    ubuntu 10.04.4版本第一次安装注意点和说明
    蓝海讯通OneAPM产品简介
    联想3650 X型号服务器的raid划分
    linux服务器更换主板后无法识别网卡(网卡启动失败)解决办法
    raid技术与应用(一)
  • 原文地址:https://www.cnblogs.com/weeping/p/7680505.html
Copyright © 2011-2022 走看看