zoukankan      html  css  js  c++  java
  • POJ

    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
    ");
    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
    ",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 }    
    
    
    
     
  • 相关阅读:
    [百度贴吧]飞腾1500a .VS. 龙芯3a3000: 同频实用性能对比
    内网环境安全整改简单办法
    PowerPoint储存此文件时发生错误 出现错误的问题解决方法
    灰阶
    Delphi实现窗体内嵌其他应用程序窗体
    access数据库用sql语句添加字段,修改字段,删除字段
    Bootstrap IIFE
    ZUI前段框架简介
    Win7去除桌面残影的方法
    Delphi中window消息截获的实现方式(2)
  • 原文地址:https://www.cnblogs.com/zmin/p/6786270.html
Copyright © 2011-2022 走看看