POJ 3665 iCow(模拟)

题意:有N首歌曲,播放的顺序按照一定的规则,输出前T首被播放的歌的编号。规则如下:

1、每首歌有一个初始的等级r,每次都会播放当前所有歌曲中r最大的那首歌(若r最大的有多首,则播放编号最小的那首歌)。

2、当某首歌被播放完后,它的等级r会变成0,而且它的r会被均分到其他N-1首歌里,若均分后还有剩余,则将剩余的将会分给剩下N-1首歌。(按照这N-1首歌编号从小到大的顺序,每首歌分1个)

3、每播放完一首歌都会执行一遍条件2。

分析:注意N=1时特判,否则除数不能为0。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
    if(fabs(a - b) < eps) return 0;
    return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 20000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
struct Node{
    int x, id;
    bool operator <(const Node&rhs)const{
        return x > rhs.x || (x == rhs.x && id < rhs.id);
    }
}num[MAXN];
bool cmp(const Node&a, const Node&b){
    return a.id < b.id;
}
int main(){
    int N, T;
    scanf("%d%d", &N, &T);
    for(int i = 0; i < N; ++i){
        scanf("%d", &num[i].x);
        num[i].id = i + 1;
    }
    if(N == 1){
        for(int i = 0; i < T; ++i) printf("1\n");
        return 0;
    }
    while(T--){
        sort(num, num + N);
        printf("%d\n", num[0].id);
        int tmp = num[0].id;
        int ave = num[0].x / (N - 1);
        int yu = num[0].x % (N - 1);
        num[0].x = 0;
        for(int i = 1; i < N; ++i){
            num[i].x += ave;//它的r会被均分到其他N-1首歌里
        }
        sort(num, num + N, cmp);
        int cnt = 0;
        for(int i = 0; ; ++i){
            if(cnt == yu) break;
            if(tmp != num[i].id){
                ++num[i].x;
                ++cnt;
            }
        }
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6479941.html