zoukankan      html  css  js  c++  java
  • Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心

    C. Polycarp at the Radio

    题目连接:

    http://codeforces.com/contest/723/problem/C

    Description

    Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence a1, a2, ..., an, where ai is a band, which performs the i-th song. Polycarp likes bands with the numbers from 1 to m, but he doesn't really like others.

    We define as bj the number of songs the group j is going to perform tomorrow. Polycarp wants to change the playlist in such a way that the minimum among the numbers b1, b2, ..., bm will be as large as possible.

    Find this maximum possible value of the minimum among the bj (1 ≤ j ≤ m), and the minimum number of changes in the playlist Polycarp needs to make to achieve it. One change in the playlist is a replacement of the performer of the i-th song with any other group.

    Input

    The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 2000).

    The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the performer of the i-th song.

    Output

    In the first line print two integers: the maximum possible value of the minimum among the bj (1 ≤ j ≤ m), where bj is the number of songs in the changed playlist performed by the j-th band, and the minimum number of changes in the playlist Polycarp needs to make.

    In the second line print the changed playlist.

    If there are multiple answers, print any of them.

    Sample Input

    4 2
    1 2 3 2

    Sample Output

    2 1
    1 2 1 2

    Hint

    题意

    有一个歌单,歌单上面有n首歌,你喜欢1,2,3....m号乐队唱的歌。

    你希望改变这个歌单,使得你喜欢的乐队们唱歌唱得最少的尽量大。

    问你最少修改多少次,且输出方案。

    题解:

    显然是每个乐队演唱n/m首歌,然后我们就维护一下这个就好了。

    贪心的for两次。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 2005;
    int n,m;
    int a[maxn];
    int cnt[maxn],vis[maxn];
    int ans2=0;
    int main()
    {
        scanf("%d%d",&n,&m);
    	for(int i=1;i<=n;i++)
    		scanf("%d",&a[i]);
    	int ans1=n/m;
    	int p=n%m;
    	for(int i=1;i<=n;i++)
    	{
    		if(a[i]>m)continue;
    		if(cnt[a[i]]>=ans1)continue;
    		cnt[a[i]]++;
    		vis[i]=1;
    	}
    	for(int i=1;i<=n;i++)
    	{
    		if(vis[i])continue;
    		int Ans1=1e9,Ans2=1e9;
    		for(int j=1;j<=m;j++)
    		{
    			if(cnt[j]<Ans2)
    				Ans2=cnt[j],Ans1=j;
    		}
    		if(Ans2==ans1)continue;
    		ans2++;
    		cnt[Ans1]++,a[i]=Ans1;
    	}
    	cout<<ans1<<" "<<ans2<<endl;
    	for(int i=1;i<=n;i++)
    		cout<<a[i]<<" ";
    	cout<<endl;
    }
  • 相关阅读:
    c#基础 里氏转换
    c#基础 base和this的区别,在继承上面
    c#基础值类和引用类型_字符串
    c# 基础字符串
    c#基础-构造函数 this new
    c#基础3-方法的重载静态和非静态,字段属性,方法
    c#基础2-out-ref
    .net的基础知识点
    Xamarin.Form的坑
    weboack 4 tutorial
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5930084.html
Copyright © 2011-2022 走看看