首页 > 代码库 > NWERC2016E - Exam Redistribution

NWERC2016E - Exam Redistribution

题目大意

求一个访问n个房间的顺序,在第一个房间你会收齐里面人的所有卷子,之后每经过一个房间,先给里面人每人先发一张手上的卷子,再收齐他们本来的试卷,使得没有人批改自己的卷子且能发到每个人(过程中手中卷子数不为负)

简要题解

按房间从大到小顺序来,若最大房间内人数大于总人数一半,geigei

#include <bits/stdc++.h>
using namespace std;
namespace my_header {
#define pb push_back
#define mp make_pair
#define pir pair<int, int>
#define vec vector<int>
#define pc putchar
#define clr(t) memset(t, 0, sizeof t)
#define pse(t, v) memset(t, v, sizeof t)
#define bl puts("")
#define wn(x) wr(x), bl
#define ws(x) wr(x), pc(‘ ‘)
    const int INF = 0x3f3f3f3f;
    typedef long long LL;
    typedef double DB;
    inline char gchar() {
        char ret = getchar();
        for(; (ret == \n || ret == \r || ret ==  ) && ret != EOF; ret = getchar());
        return ret; }
    template<class T> inline void fr(T &ret, char c =  , int flg = 1) {
        for(c = getchar(); (c < 0 || 9 < c) && c != -; c = getchar());
        if (c == -) { flg = -1; c = getchar(); }
        for(ret = 0; 0 <= c && c <= 9; c = getchar())
            ret = ret * 10 + c - 0;
        ret = ret * flg; }
    inline int fr() { int t; fr(t); return t; }
    template<class T> inline void fr(T&a, T&b) { fr(a), fr(b); }
    template<class T> inline void fr(T&a, T&b, T&c) { fr(a), fr(b), fr(c); }
    template<class T> inline char wr(T a, int b = 10, bool p = 1) {
        return a < 0 ? pc(-), wr(-a, b, 0) : (a == 0 ? (p ? pc(0) : p) : 
            (wr(a/b, b, 0), pc(0 + a % b)));
    }
    template<class T> inline void wt(T a) { wn(a); }
    template<class T> inline void wt(T a, T b) { ws(a), wn(b); }
    template<class T> inline void wt(T a, T b, T c) { ws(a), ws(b), wn(c); }
    template<class T> inline void wt(T a, T b, T c, T d) { ws(a), ws(b), ws(c), wn(d); }
    template<class T> inline T gcd(T a, T b) {
        return b == 0 ? a : gcd(b, a % b); }
    template<class T> inline T fpw(T b, T i, T _m, T r = 1) {
        for(; i; i >>= 1, b = b * b % _m)
            if(i & 1) r = r * b % _m;
        return r; }
};
using namespace my_header;

int a[111], b[111];

bool cmp(int i, int j) {
    return a[i] > a[j];
}

int main() {
#ifdef lol
    freopen("E.in", "r", stdin);
    freopen("E.out", "w", stdout);
#endif
    int n = fr(), sum = 0;
    for (int i = 1; i <= n; ++i) {
        fr(a[i]);
        b[i] = i;
        sum += a[i];
    }
    sort(b + 1, b + n + 1, cmp);
    if (a[b[1]] * 2 > sum) {
        printf("impossible");
    } else {
        for (int i = 1; i <= n; ++i)
            printf("%d ", b[i]);
        puts("");
    }

    return 0;
}

 

NWERC2016E - Exam Redistribution