Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心

题目地址:这里
题意:有一个歌单,歌单上面有n首歌,你喜欢1,2,3….m号乐队唱的歌。你希望改变这个歌单,使得你喜欢的乐队们唱歌唱得最少的尽量大。问你最少修改多少次,且输出方案。
解法: 显然是每个乐队演唱n/m首歌,然后我们就维护一下这个就好了。贪心的for两次。

//CF 723C

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int n, m, a[maxn], cnt[maxn], vis[maxn];
int ans1, ans2 = 0;
int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int ans1 = 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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值