列表

详情


NC24947. [USACO 2008 Jan B]iCow

描述

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.

输入描述

* Line 1: Two space-separated integers: N and T
* Lines 2..N+1: Line i+1 contains a single integer: Ri

输出描述

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

示例1

输入:

3 4
10
8
11

输出:

3
1
2
3

说明:

The iCow contains 3 songs, with ratings 10, 8, and 11, respectively. You must determine the first 4 songs to be played.

The ratings before each song played are:
R1 R2 R3
10 8 11 -> play #3 11/2 = 5, leftover = 1
16 13 0 -> play #1 16/2 = 8
0 21 8 -> play #2 21/2 = 10, leftover = 1
11 0 18 -> play #3 ...

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 7ms, 内存消耗: 376K, 提交时间: 2019-08-02 16:39:49

#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
int n,T,r[1100],x,te;
int main(){
	scanf("%d%d",&n,&T);
	fo(i,1,n) scanf("%d",&r[i]);
	while (T--){
		x=1;
		fo(i,2,n) if (r[i]>r[x]) x=i;
		printf("%d\n",x);
		te=r[x]/(n-1);
		fo(i,1,n) if (i!=x) r[i]+=te;
		te=r[x]%(n-1);
		r[x]=0;
//		fo(i,1,te) r[i]++;
		if (te) fo(i,1,n) if (i!=x){
			te--;
			r[i]++;
			if (!te) break;
		}
	}
	return 0;
}

C++11(clang++ 3.9) 解法, 执行用时: 14ms, 内存消耗: 588K, 提交时间: 2020-02-26 17:09:34

#include<cstdio>
int n,t,r[1007],maxi=1;
int main()
{
	scanf("%d%d",&n,&t);
	for(int i=1;i<=n;i++)
	scanf("%d",&r[i]),maxi=r[maxi]<r[i]?i:maxi;
	while(t--)
	{
		printf("%d\n",maxi);
		for(int i=1;i<=n;i++)
		if(i!=maxi) r[i]+=r[maxi]/(n-1);
		int cnt=r[maxi]%(n-1);r[maxi]=0;
		for(int i=1;cnt--;i++)
		if(i!=maxi) ++r[i];
		else ++cnt;
		maxi=1;
		for(int i=1;i<=n;i++)
		maxi=r[maxi]<r[i]?i:maxi;
	 } 
	 return 0;
}

上一题