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;
    }
  • 相关阅读:
    第一章 工欲善其事 必先利其器—Android SDK工具(3)
    UVa 11063
    Remember the Word,LA3942(Trie树+DP)
    Atitit.Gui控件and面板----数据库区-mssql 2008 权限 配置 报表查看成员
    Android手机令牌教程
    cocos2d-x 在mac下执行 demo
    Install Oracle 10g on Red Hat Linux 5.3 Step by Step
    Python根据内嵌的数字将字符串排序(sort by numbers embedded in strings)
    mysql一次运行多个SQL文件
    CentOS/Linux 卸载MATLAB
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5930084.html
Copyright © 2011-2022 走看看