codeforces723----C. Polycarp at the Radio

 1 //AC代码。。。表示很晕
 2 #include <iostream>
 3 using namespace std;
 4 int a[2005],b[2005];
 5 int main()
 6 {
 7     int n,m,cnt;
 8     cin >> n >> m;
 9     int t = n/m;
10     int t2 = n%m;
11     if(n%m == 0) cnt = t;
12     else cnt = t+1;
13     for(int i=0; i<n; ++i)
14     {
15         cin >> a[i];
16         if(a[i] <= m) ++b[a[i]];
17         if(a[i] <= m && t2 > 0 && b[a[i]] == cnt) --t2;
18     }
19     int f = 1;
20     int ans = 0;
21     if(t2 == 0) cnt = t;
22     //cout << cnt << endl;
23     for(int i=0; i<n; ++i)
24     {
25         if(a[i] > m ||(a[i] <=m && b[a[i]] > cnt))
26         {
27             while(f <= m)
28             {
29                 //cout <<"test" << f << "  " << cnt << endl;
30                 if(b[f] < t) break;
31                 ++f;
32             }
33             if(f <= m)
34             {
35                 ++ans;
36                 if(a[i] <= m)
37                     --b[a[i]];
38                 a[i] = f;
39                 ++b[f];
40                 //cout <<t2 << "bf " << b[f] <<"    " << cnt << endl;
41                 if(t2 > 0 && b[f] == cnt )
42                     if((--t2) == 0) cnt = t;
43                 if(a[i] <= m && t2 > 0 && b[a[i]] == cnt)
44                     if((--t2) == 0) cnt = t;
45             }
46         }
47     }
48     cout << t << " " << ans << endl;
49     for(int i=0; i<n; ++i)
50         if(i == 0)
51             cout << a[i];
52         else
53             cout << " " << a[i];
54     cout << endl;
55     return 0;
56 }
原文地址:https://www.cnblogs.com/qq188380780/p/7266357.html