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 }
  • 相关阅读:
    回顾2018,展望2019
    NLog日志框架使用探究-1
    基于NetMQ的TLS框架NetMQ.Security的实现分析
    鸟哥的Linux私房菜笔记第五章,文件权限与目录配置(二)
    鸟哥的Linux私房菜笔记第五章,文件权限与目录配置(一)
    鸟哥的Linux私房菜笔记第四章
    ThinkPHP5.1 + tufanbarisyildirim 解析apk
    Java核心技术第八章——泛型程序设计(1)
    Java核心技术第五章——2.Object类
    Java核心技术第五章——1.类、超类、子类(2)
  • 原文地址:https://www.cnblogs.com/jiamian/p/11261757.html
Copyright © 2011-2022 走看看