题意:给定 n 个数,让把某一些变成 1-m之间的数,要改变最少,使得1-m中每个数中出现次数最少的尽量大。

析:这个题差不多读了一个小时吧,实在看不懂什么意思,其实并不难,直接暴力就好,n m不大。很明显最后1-m中次数最长的应该是n/m,

所以我们把大于n/m的都变成小于等于的,把这 n 个数中大于 m 的也变成,但是并不需要都变,只要满足每个数都是大于等于n/m就好了。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 2e3 + 5;
const LL mod = 1e9 + 7;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
inline int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int a[maxn], b[maxn]; int main(){
while(scanf("%d %d", &n, &m) == 2){
memset(b, 0, sizeof b);
for(int i = 1; i <= n; ++i){
scanf("%d", a+i);
if(a[i] <= m) ++b[a[i]];
} int ans1 = n / m;
int ans2 = 0; int cnt = 1;
for(int i = 1; i <= n; ++i) if(a[i] <= m && b[a[i]] > ans1){
--b[a[i]];
for(int j = cnt; j <= m; ++j){
if(b[j] < ans1) { ++b[j]; cnt = j; a[i] = j; ++ans2; break; }
}
}else if(a[i] > m){
for(int j = cnt; j <= m; ++j){
if(b[j] < ans1) { ++b[j]; cnt = j; a[i] = j; ++ans2; break; }
}
} printf("%d %d\n", ans1, ans2);
for(int i = 1; i <= n; ++i)
if(i == 1) printf("%d", a[i]);
else printf(" %d", a[i]);
printf("\n");
}
return 0;
}

CodeForces 723C Polycarp at the Radio (题意题+暴力)的更多相关文章

  1. Codeforces 723C. Polycarp at the Radio 模拟

    C. Polycarp at the Radio time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  2. codeforces 723C : Polycarp at the Radio

    Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...

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

    C. Polycarp at the Radio time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  4. Codeforces 659F Polycarp and Hay 并查集

    链接 Codeforces 659F Polycarp and Hay 题意 一个矩阵,减小一些数字的大小使得构成一个连通块的和恰好等于k,要求连通块中至少保持一个不变 思路 将数值从小到大排序,按顺 ...

  5. Codeforces Round #310 (Div. 2)--A(简单题)

    http://codeforces.com/problemset/problem/556/A 题意:给一个01字符串,把所有相邻的0和1去掉,问还剩下几个0和1. 题解:统计所有的0有多少个,1有多少 ...

  6. CodeForces - 669D Little Artem and Dance 想法题 多余操作

    http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...

  7. Codeforces 659F Polycarp and Hay【BFS】

    有毒,自从上次选拔赛(哭哭)一个垃圾bfs写错之后,每次写bfs都要WA几发...好吧,其实也就这一次... 小白说的对,还是代码能力不足... 非常不足... 题目链接: http://codefo ...

  8. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  9. CodeForces 1005D Polycarp and Div 3(思维、贪心、dp)

    http://codeforces.com/problemset/problem/1005/D  题意: 给一个仅包含数字的字符串,将字符串分割成多个片段(无前导0),求这些片段里最多有多少是3的倍数 ...

随机推荐

  1. [NOIP1998] 普及组

    三连击 题目描述 将1,2,…,9共9个数分成三组,分别组成三个三位数,且使这三个三位数构成1:2:3的比例,试求出所有满足条件的三个三位数. 输入输出格式 输入格式: 木有输入 输出格式: 若干行, ...

  2. Codeforces 653D Delivery Bears【二分+网络流】

    题目链接: http://codeforces.com/problemset/problem/653/D 题意: x个熊拿着相同重量的物品,从1号结点沿着路走到N号结点,结点之间有边相连,保证可以从1 ...

  3. java课堂测试—根据模板完成一个简单的技术需求征集系统

    课堂上老师发布了一个页面模板要求让我们实现一个系统的功能,模仿以后后端的简单工作情况. 然后在这个模板的基础上,提供了一个注册的网页模板,接着点击注册的按钮,发现register里面调用了zhu/zh ...

  4. Spring中基于AOP的XML架构

    以下内容引用自http://wiki.jikexueyuan.com/project/spring/aop-with-spring-framenwork/xml-schema-based-aop-wi ...

  5. 创立一个站点的前前后后(起因,域名,云平台,备案,CDN等等)(1)

    起因 写完<完美软件开发:方法与逻辑>这书后,原本想继续写书的,可出来參加了些社区活动后,我发现我写的书大家评价还行.但事实上不太理解.而接下来想写的书更加抽象点.准备叫<管理的解析 ...

  6. android多个fragment返回键层层返回

    在FragmentActivity的fragment跳转的时候加入到执行栈. public void switchFrag(BaseFragment to) { getSupportFragmentM ...

  7. Office PDF如何旋转页面之后保存

    直接视图-旋转视图-逆时针,是不行的,旋转之后无法保存,另存为之后也再打开也没有效果.   要点击视图-工具-页面   然后在右边的菜单中点击旋转,然后执行旋转,然后就可以保存了.        

  8. 记一次Tomcat无法正常启动的查错与解决之路

    使用LombozEclipse运行某Web应用,结果总是404. 换另一个Eclipse运行,还是404. 换Tomcat到更高版本,还是404. 直接启动Tomcat,闪退. 用重定向拦截输出,可惜 ...

  9. 多媒体开发之---h.264 rtsp网络流测试流

    rtsp://218.204.223.237:554/live/1/66251FC11353191F/e7ooqwcfbqjoo80j.sdp 珠海拱北

  10. 另外几种Java集合框架具体解释续

    另外几种Java集合框架具体解释续 作者:chszs,未经博主同意不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs fastutil库优于Trove库的 ...