Codeforces 723C暴力(最小值最大)

点击打开链接

#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#define M 2016 
using namespace std;
const int inf=1<<20;
int a[M],b[M];//b[j] the num of songs the groups j plays 
map<int,int> num;
int main()
{
	
	int n,m;
	cin>>n>>m;
	//要让1~m的人played 
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<=m)
		{
			num[a[i]]++;
		}
	}
	int cur=1; 
	int ans=n/m;//n首歌分给m个人最小值要最大->平均分 
	int cnt=0;//最小修改次数 若都1~m的次数都达到ans则不用修改 
	// 4 3 
	//1 2 3 4  
	
	for(int i=1;i<=n;i++)
	{
		if(a[i]>m||num[a[i]]>ans)
		{
			while(cur<=m&&num[cur]>=ans)//跳过已经达到ans的数字 
			{
				cur++;
			}
			if(cur<=m)//还有数字没达到ans时要修改 
			{
				cnt++;
				num[a[i]]--; 
				a[i]=cur;
				num[cur]++;
			}
			
		}
	}
	cout<<ans<<" "<<cnt<<endl;
	for(int i=1;i<=n;i++)
	{
		cout<<a[i];
		if(i==n)
		cout<<endl;
		else
		cout<<" ";
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值