Codeforces Round #375 (Div. 2) C
来源:互联网 发布:网络通网站怎么买 编辑:程序博客网 时间:2024/06/06 21:40
题目传送门:http://codeforces.com/contest/723/problem/C
题意:给n首歌曲1,2...n然后a1,a2,...an表示1th歌曲由a1th乐队演唱,小明喜欢前m个乐队,小明可以随意改变歌曲的演唱者,问最少要操作多少次才能让小明喜欢的乐队中唱歌最少的乐队唱的歌尽量多,输出最少乐队唱的歌曲数,最少操作次数,操作后的演唱名单
思路:昨天比赛的时候没做出来,当时思路其实并不清楚就开始敲,结果越敲越糊涂,今天早上起来再看看,发现并不是难题,暴力就好了。关键是先找出最少乐队唱的歌曲数,最少操作次数。然后再做这题就简单好多了。昨天可能是stl题做多了,就各种stl瞎搞,也没搞出来。反正n,m都是2000,暴力就可以,而且暴力后发现时间用的也不是很多。
代码如下:
#include <iostream>#include <algorithm>#include <cstring>#include <stdio.h>#include <string>#include <cmath>#include <queue>#include <set>#include <map>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define ll long long#define ull unsigned long long#define mem(n,v) memset(n,v,sizeof(n))#define MAX 2005#define MAXN 2000005#define PI 3.1415926#define E 2.718281828459#define opnin freopen("text.in.txt","r",stdin)#define opnout freopen("text.out.txt","w",stdout)#define clsin fclose(stdin)#define clsout fclose(stdout)#define haha1 cout << "haha1"<< endl#define haha2 cout << "haha2"<< endl#define haha3 cout << "haha3"<< endlconst int INF = 0x3f3f3f3f;const ll INFF = 0x3f3f3f3f3f3f3f3f;const double pi = 3.141592653589793;const double inf = 1e18;const double eps = 1e-8;const ll mod = 1e9+7;const ull mx = 133333331;int a[MAX]; //key:song,value:bandint b[MAX]; //key:band,value:song_numberstruct like{ int songnum; int band; friend bool operator < (like a,like b){ return a.songnum < b.songnum; } like(int b = 0,int s = 0):songnum(s),band(b) {}};like lll[MAX];int main(){ mem(b,0); int n,m; cin >> n >> m; int cnt = 0; int g = 0; int ans = n / m; for(int i=1;i<=n;i++){ scanf("%d",a+i); if(a[i] <= m) b[a[i]]++; else g++; } for(int i=1;i<=m;i++){ if(b[i] < ans) cnt += (ans-b[i]); } int cnt1 = cnt; for(int i=1;i<=m;i++){ lll[i].band = i; lll[i].songnum = b[i]; } sort(lll+1,lll+m+1); while(cnt > 0){ if(g >0){ for(int i=1;i<=n;i++){ if(a[i] > m){ lll[1].songnum++; g--; cnt--; a[i] = lll[1].band; break; } } sort(lll+1,lll+m+1); } else{ for(int i=1;i<=n;i++){ if(a[i] == lll[m].band){ lll[1].songnum++; lll[m].songnum--; cnt--; a[i] = lll[1].band; break; } } sort(lll+1,lll+m+1); } } cout << ans << ' ' << cnt1 <<endl; for(int i=1;i<=n;i++){ printf("%d ",a[i]); } return 0;}
0 0
- Codeforces Round #375 (Div. 2) C
- Codeforces Round #375 (Div. 2) C
- Codeforces Round #375 (Div. 2) C (贪心)
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #375 (Div. 2)
- Codeforces Round #375 (Div. 2)
- Codeforces Round #375 (Div. 2)
- Codeforces Round #375 (Div. 2)
- Codeforces Round #375 (Div. 2)
- Codeforces Round #375 (Div. 2)
- Codeforces Round #375 (Div. 2)
- Codeforces Round #375 (Div. 2)-C. Polycarp at the Radio
- Codeforces Round #375 (Div. 2) A&B&C
- Codeforces Round #375 (Div. 2)C. Polycarp at the Radio
- Codeforces Round #375 (Div. 2) C Polycarp at the Radio
- Codeforces Round #105 (Div. 2) C
- Codeforces Round 134 div 2 C题
- Codeforces Round #137 (Div. 2), problem: (C)
- 二叉树的实现
- 救济金发放The Dole Queue
- java assert 断言
- vim
- 树的存储结构
- Codeforces Round #375 (Div. 2) C
- 走势N2的判断
- 排序 —— 希尔排序(Shell sort)
- 【机器学习】梯度、Hessian矩阵、平面方程的法线以及函数导数的含义
- POJ2528线段树变体
- 134. Gas Station
- C++ HDU 2005 第几天
- struts1
- linux入门--文件的打包压缩