Algoogle

Algorithm for Programming Contest

PKU 3665 iCow

Category: PKU Tag: implementation

iCow

問題概要


解法


毎回ループを回してシミュレーション

コード


(3665.cpp) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <cstdio>

using namespace std;

int N, T, R[10010], MR, id;

int main(){
    scanf("%d%d", &N, &T);
    for(int i = 0; i < N; i++){
        scanf("%d", R+i);
        if(R[i] > MR){
            MR = R[i];
            id = i;
        }
    }
    if(N == 1) while(T --> 0) puts("1");
    else while(T --> 0){
            printf("%d\n", id+1);
            int tid = id, tMR = 0, res = R[id] % (N-1);
            R[id] = 0;
            for(int i = 0; i < N; i++)
                if(i != id){
                    R[i] += MR / (N-1);
                    if(res) R[i]++, res--;
                    if(tMR < R[i]){
                        tMR = R[i];
                        tid = i;
                    }
                }
            id = tid;
            MR = tMR;
    }
    return 0;
}

Comments