POJ iCow
来源:互联网 发布:win10软件乱码 编辑:程序博客网 时间:2024/06/07 18:50
Description
Fatigued by the endless toils of farming, Farmer John has decided to try his hand in the MP3 player market with the new iCow. It is an MP3 player that storesN songs (1 ≤ N ≤ 1,000) indexed 1 through N that plays songs in a "shuffled" order, as determined by Farmer John's own algorithm:
- Each song i has an initial rating Ri (1 ≤Ri ≤ 10,000).
- The next song to be played is always the one with the highest rating (or, if two or more are tied, the highest rated song with the lowest index is chosen).
- After being played, a song's rating is set to zero, and its rating points are distributed evenly among the otherN-1 songs.
- If the rating points cannot be distributed evenly (i.e., they are not divisible byN-1), then the extra points are parceled out one at a time to the first songs on the list (i.e.,R1 , R2 , etc. -- but not the played song) until no more extra points remain.
Determine the first T songs (1 ≤ T ≤ 1000) that are played by the iCow.
Input
* Line 1: Two space-separated integers:N and T
* Lines 2..N+1: Line i+1 contains a single integer: Ri
题目大意
1.每首歌均有其对应权值:Ri
2.当前要播放的歌必须是当前所有歌曲中权值最大的一首(若最高值出现多个,则取编号最小的)
3.当一首歌播放完毕时,该歌的权值平均分给其他(N-1)首歌,当前歌曲权值变为0
4.若3中当前歌曲的权值不能整除(N-1),则先把能整除的部分按3的要求分配,余数部分从编号1
开始每首歌曲得1分(不包括当前歌曲),直到全部分完为止。当前歌曲权值变为0。
Output
* Lines 1..T: Line i contains a single integer that is the i-th song that the iCow plays.
Sample Input
3 410811
Sample Output
3123
题解
数据太小,n^2就过了,根本不用堆。
#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<cmath>using namespace std;int n,m,a[1002];int main(){scanf("%d%d",&n,&m);for(int i=1;i<=n;i++) scanf("%d",&a[i]);for(int i=1;i<=m;i++) {int maxs=0,w;for(int j=1;j<=n;j++) {if(a[j]>maxs) {maxs=a[j]; w=j;} } printf("%d\n",w); int p=a[w]/(n-1),q=a[w]%(n-1); a[w]=0; for(int j=1;j<=n;j++) {if(j!=w) {a[j]+=p; if(q) {a[j]++; q--;} } } }return 0;}
- POJ iCow
- iCow POJ
- [水] poj 3665 iCow
- poj 3665 icow
- POJ 3665 iCow 再想想
- iCow player
- luogu2035 iCow
- 【USACO】iCow播放器
- (Relax ST1.27)POJ 3665 iCow(将一个数分给其他数的处理方式:整出和不整除部分)
- JZOJ__Day 10:【普及模拟】【USACO】iCow播放器
- jzoj 1676. 【USACO】iCow播放器 (Standard IO)
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- 关于xdais
- com.wanju.project001.zonghe.common.interfaces ,mybatis异常
- Android 图片三级缓存之内存缓存(告别软引用(SoftRefrerence)和弱引用(WeakReference))
- VS2010入门
- Android SkImageDecoder::Factory returned null
- POJ iCow
- 学习笔记20140513
- Formsets 阅读笔记
- 如何使用苹果开发证书
- HDU 4565 So Easy!
- 软件开发心得点滴记录
- IOS成长之路-ASIFormDataRequest实现上传图片
- Js Object to JSONString
- Oracle Stream Replication技术