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 stores N 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 other N-1 songs.
  • If the rating points cannot be distributed evenly (i.e., they are not divisible by N-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.

This process is repeated with the new ratings after the next song is played.

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

Output

* Lines 1..T: Line i contains a single integer that is the i-th song that the iCow plays.

Sample Input

3 4
10
8
11

Sample Output

3
1
2
3

这题的坑在于红字部分的理解,无法平均分的point从第一个开始,每个cow分一个,直到分完。
挺难读的 :(
 1 #include<cstdio>
2 #define Max 1111
3 int cow[Max];
4 int main()
5 {
6 int n,t;
7 int max=-1,maxi;
8 int left=0,add=0;
9 while(~scanf("%d %d",&n,&t))
10 {
11 for(int i=1;i<=n;i++)
12 scanf("%d",&cow[i]);
13 if(n==1) //这个条件不加也能过
14 { //但题目上n取值明明可以等于1
15 while(t--) //不知道是题意我没有理解透,还是数据水
16 printf("1\n");
17 }
18 else
19 {
20 for(int k=0;k<t;k++)
21 {
22 for(int i=1;i<=n;i++)
23 {
24 if(max<cow[i])
25 {
26 maxi=i;
27 max=cow[i];
28 }
29 }
30 printf("%d\n",maxi);
31 left=max%(n-1);
32 add=max/(n-1);
33 cow[maxi]=0;
34 max=-1;
35 for(int j=1;j<=n;j++)
36 {
37 if(j==maxi)continue;
38 if(left)
39 {
40 cow[j]++;
41 left--;
42 }
43 cow[j]+=add;
44 }
45 }
46 }
47 }
48 return 0;
49 }

 

POJ - 3665 icow的更多相关文章

  1. POJ - 3665 iCow(模拟)

    题意:有N首歌曲,播放的顺序按照一定的规则,输出前T首被播放的歌的编号.规则如下: 1.每首歌有一个初始的等级r,每次都会播放当前所有歌曲中r最大的那首歌(若r最大的有多首,则播放编号最小的那首歌). ...

  2. POJ 3665 模拟

    按照题意模拟就OK了 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...

  3. poj-3665 iCow(暴力吧)

    http://poj.org/problem?id=3665 题目描述 Fatigued by the endless toils of farming, Farmer John has decide ...

  4. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  5. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  6. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  7. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  8. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. SAP 修改数据元素 注意事项

    在修改数据元素的时候,通常要注意一下几点: 1.在修改完数据元素后,如果激活不成功,那么就要通过SE14进入数据库实用程序,在对象名处输入数据元素相关联的表的名称 下面词典对象选择表,然后点击编辑,处 ...

  2. 特斯拉Toolbox诊断检测仪工具Tesla诊断电脑 Tesla Toolbox

    Tesla特斯拉Toolbox诊断工具Tesla诊断电脑检测仪 Tesla Toolbox, Tesla Toolbox Diagnostic Tester.Language: English,Deu ...

  3. Nginx(七):location的使用以及nginx关闭原理

    上一篇中,我们了解了如何nginx的配置原则及解析框架,以及解析location配置的具体实现,相信大家对该部分已经有了比较深刻的认识. 本篇,我们进一步来了解下,解析之后的配置,如何应用到实际中的吧 ...

  4. css-前端实现左中右三栏布局的常用方法:绝对定位,圣杯,双飞翼,flex,table-cell,网格布局等

    1.前言 作为一个前端开发人员,工作学习中经常会遇到快速构建网页布局的情况,这篇我整理了一下我知道的一些方法.我也是第一次总结,包括圣杯布局,双飞翼布局,table-cell布局都是第一次听说,可能会 ...

  5. 一个关于时区的bug

    起因: 在 Apollo 中配置了某活动的开始时间是 2020-05-15, 代码中的逻辑判断如下: const nowTime = new Date().getTime(); const start ...

  6. Lucene 查询原理 传统二级索引方案 倒排链合并 倒排索引 跳表 位图

    提问: 1.倒排索引与传统数据库的索引相比优势? 2.在lucene中如果想做范围查找,根据上面的FST模型可以看出来,需要遍历FST找到包含这个range的一个点然后进入对应的倒排链,然后进行求并集 ...

  7. 能够满足这样要求的哈希算法有很多,其中比较著名并且应用广泛的一个哈希算法,那就是MurmurHash 算法。尽管这个哈希算法在 2008 年才被发明出来,但现在它已经广泛应用到 Redis、MemCache、Cassandra、HBase、Lucene 等众多著名的软件中。

    能够满足这样要求的哈希算法有很多,其中比较著名并且应用广泛的一个哈希算法,那就是MurmurHash 算法.尽管这个哈希算法在 2008 年才被发明出来,但现在它已经广泛应用到 Redis.MemCa ...

  8. socket更多方法

    一.socket的更多方法介绍 ###socket更多方法服务端套接字函数 s.bind() 绑定(主机,端口号)到套接字 s.listen() 开始TCP监听 s.accept() 被动接受TCP客 ...

  9. 关于ckfinder上传文件时不能根据结果返回自定义操作问题?

    最近项目中为了便于文件的管理,所以CMS项目中使用到了ckfinder插件,但是在使用的过程中,发现其自带的上传事件,如果上传重名的文件,该工具会自动提示错误,显示上传失败.但是如果想要自己去处理重名 ...

  10. hadoop的Namenode HA原理详解

    为什么要Namenode HA? 1. NameNode High Availability即高可用. 2. NameNode 很重要,挂掉会导致存储停止服务,无法进行数据的读写,基于此NameNod ...