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 }
时间: 2024-11-25 05:25:58

codeforces723----C. Polycarp at the Radio的相关文章

cf723c Polycarp at the Radio

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 d

CodeForces 723C Polycarp at the Radio (题意题+暴力)

题意:给定 n 个数,让把某一些变成 1-m之间的数,要改变最少,使得1-m中每个数中出现次数最少的尽量大. 析:这个题差不多读了一个小时吧,实在看不懂什么意思,其实并不难,直接暴力就好,n m不大.很明显最后1-m中次数最长的应该是n/m, 所以我们把大于n/m的都变成小于等于的,把这 n 个数中大于 m 的也变成,但是并不需要都变,只要满足每个数都是大于等于n/m就好了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&

【Codeforces 723C】Polycarp at the Radio 贪心

n个数,用最少的次数来改变数字,使得1到m出现的次数的最小值最大.输出最小值和改变次数以及改变后的数组. 最小值最大一定是n/m,然后把可以改变的位置上的数变为需要的数. http://codeforces.com/problemset/problem/723/C Examples input 4 21 2 3 2 output 2 11 2 1 2 input 7 31 3 2 2 2 2 1 output 2 11 3 3 2 2 2 1 input 4 41000000000 100 7

CodeForces 723C Polycarp at the Radio

构造. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #incl

Codeforces Round #375 (Div. 2) ABCDE

A - The New Year: Meeting Friends 水 #include<iostream> #include<algorithm> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; cout<<max(a,max(b,c)) - min(a,min(b,c)) <<endl; return 0; } B - Text Document A

洛谷 P3133 [USACO16JAN]无线电联系Radio Contact

P3133 [USACO16JAN]无线电联系Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to help him find it! They both fan out and search the farm along different paths, but stay in contact via radio so they can keep in to

微信小程序组件解读和分析:十三、radio单选项目

radio单选项目组件说明: radio:单选项目. radio-group: 单项选择器,内部由多个<radio/>组成. radio单选项目示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 <view class="page">   <view class="page__hd">     <text

Jquery实际应用,判断radio,selelct,checkbox是否选中及选中的值

jquery取radio单选按钮的值 $("input[name='items']:checked").val(); 另:判断radio是否选中并取得选中的值 如下所示: function checkradio(){ var item = $(":radio:checked"); var len=item.length; if(len>0){ alert("yes--选中的值为:"+$(":radio:checked")

jquery控制radio选中

好久没写jquery了,昨天下午写一个效果,结果倒腾了半天还是没有解决,好在今天早上在网上询问到解决方法了,现在果断记录下. 要实现的效果就是交易方式选择时不同的交易方式下默认选中第一个选项. 如下: 支付宝,借记卡,信用卡 是三个大选项卡. 点击每个选项卡默认选中该选项卡下首个radio控件,所有选项卡下的radio的name都是相同的. 之前写的错误的是radio标签上已经添加了选中属性,但是页面上就是不显示选中.如下:(错误例子) 1 <html> 2 <head> 3 &l