POJ 3665 iCow

  • 题面

                                               iCow

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6760 Accepted: 2457

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 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: 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

1

Source

USACO 2008 January Bronze

 
  
   

---------------------------------------------------------------------------------------------------------------------------------------------------

  • 题意

        现有一个MP3,其播放顺序及规则为:

  1. 从分值最大的开始放
  2. 播放后分之清零
  3. 清零的分数平均分给除它外的其余乐曲
  4. 若有余数则按照读入的顺序依次分给除它外的其余乐曲

       给你初始分值,让你求第一到第k次的播放顺序

---------------------------------------------------------------------------------------------------------------------------------------------------

  • 思路

        水题,直接模拟即可

---------------------------------------------------------------------------------------------------------------------------------------------------

  • std

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n,a[1050],t;
int main()
{
	cin>>n>>t;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=t;i++)
	{
		int MAX=0;
		for(int j=1;j<=n;j++)
			if(a[j]>a[MAX]) MAX=j;//确定当前最大分值乐曲的下标
		for(int j=1;j<=n;j++)
			if(j!=MAX) a[j]+=a[MAX]/(n-1);//处理可以整除的部分
		a[MAX]-=a[MAX]/(n-1)*(n-1);//减去平均分的分值
		if(a[MAX]>0)//若有余数
			for(int j=1;j<=n;j++)
			{
				if(j!=MAX) a[j]++,a[MAX]--;
				if(a[MAX]==0) break;
			}
		cout<<MAX<<endl;
	}
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值