poj3665

简单题

View Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define maxn 1005

int n, t;
int f[maxn];
bool vis[maxn];
int num;

void input()
{
    scanf("%d%d", &n, &t);
    for (int i = 0; i < n; i++)
        scanf("%d", &f[i]);
}

int cal()
{
    if (n == 1)
        return 0;
    int ret = 0;
    for (int i = 0; i < n; i++)
        if (f[i] > f[ret])
            ret = i;
    int ave = f[ret] / (n - 1);
    for (int i = 0; i < n; i++)
        if (i != ret)
            f[i] += ave;
    int left = f[ret] % (n - 1);
    for (int i = 0; left > 0; i++)
        if (i != ret)
        {
            left--;
            f[i]++;
        }
    f[ret] = 0;
    return ret;
}

int main()
{
    //freopen("t.txt", "r", stdin);
    memset(vis, 0, sizeof(vis));
    input();
    num = n;
    for (int i = 0; i < t; i++)
        printf("%d\n", cal() + 1);
    return 0;
}
posted @ 2012-07-04 15:09  金海峰  阅读(253)  评论(0编辑  收藏  举报