zoukankan      html  css  js  c++  java
  • poj-3665 iCow(暴力吧)

    http://poj.org/problem?id=3665

    题目描述

    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.

    输入

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

    刚开始以为要用优先队列,结果越写越麻烦,最后写乱了,wa了,还不如直接暴力做

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <sstream>
     6 #include <cstdio>
     7 #include <vector>
     8 #include <string>
     9 #include <cmath>
    10 #include <queue>
    11 #include <stack>
    12 #include <map>
    13 #include <set>
    14 #include <math.h>
    15  
    16 #define INF 0x3f3f3f3f
    17 #define MAXN 1005
    18 const int mod = 1e9 + 7;
    19  
    20 using namespace std;
    21  
    22 int d[MAXN];
    23  
    24 int main()
    25 {
    26     int N, K;
    27     cin >> N >> K;
    28  
    29     for (int i = 1; i <= N; i++)
    30         scanf("%d", &d[i]);
    31      
    32     while (K--) {
    33         int maxx = -1;
    34         int flag = 0;
    35         for (int i = 1; i <= N; i++)
    36             if (d[i] > maxx)
    37                 maxx = d[i], flag = i;
    38         printf("%d
    ", flag);
    39         int temp = d[flag] / (N - 1);
    40         if (temp) {
    41             for (int i = 1; i <= N; i++) {
    42                 if (i != flag)
    43                     d[i] += temp;
    44             }
    45         }
    46         temp = d[flag] % (N - 1);
    47         d[flag] = 0;
    48         if (temp) {
    49             for (int i = 1; i <= N && temp; i++) {
    50                 if (i != flag)
    51                     d[i]++, temp--;
    52             }
    53         }
    54     }
    55  
    56     return 0;
    57 }
  • 相关阅读:
    用windows下的画板画蒙娜丽莎
    记账
    谁说VISTA的游戏兼容性差?
    Silverlight3系列(四)数据绑定 Data Binding 1 Virus
    Silverlight3系列(二)Silverlight3+wcf+在不使用证书的情况下自定义用户名密码验证 Virus
    Silverlight3系列(七)数据绑定 Data Binding 3 数据类型转换 Data Converter Virus
    Silverlight3系列(六)数据验证 Data Validation Virus
    ocs2007二次开发:扩展tab标签 Virus
    Silverlight3系列(八)数据绑定 Data Binding 3 数据模板 Data Templates Virus
    Silverlight3系列(九)Silverlight 及其相关技术简介 Virus
  • 原文地址:https://www.cnblogs.com/jiamian/p/11261757.html
Copyright © 2011-2022 走看看