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 }
  • 相关阅读:
    Microsoft .NET Framework 以及 CLR 的版本
    如何:备份 Team Foundation Server
    通过VS2008SP1 访问TFS2010
    Project 2007 Understanding Project's Percent Complete vs. Percent Work Complete
    TFS:从单服务器部署移到双服务器部署
    C#网络编程(基本概念和操作) Part.1
    图解Windows server 2012故障转移群集的安装、建立
    产品经理经验总结
    TCP同步与异步及阻塞模式,多线程+阻塞模式,非阻塞模式简单介绍
    Windows Phone开发概论
  • 原文地址:https://www.cnblogs.com/weeping/p/7680505.html
Copyright © 2011-2022 走看看