UVA133 救济金发放 The Dole Queue

由于数据很小,可以使用最麻烦的方法,一步一步的模拟,然后人也不用真的去掉,只是让访问被访问过的不起作用就行了

#include 

#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pa;

int main() {
    int n, k, m;
    while (cin >> n >> k >> m) {
        if (!n && !k && !m) break;
        int pos1 = -1, pos2 = n;
        int Hash[25] = {};
        int cnt = 0;
        while (cnt < n) {
            int t1 = 0, t2 = 0;
            while (t1 < k) {
                if (pos1 < n - 1) pos1++;
                else pos1 = 0;
                if (!Hash[pos1]) t1++;
            }
            while (t2 < m) {
                if (pos2) pos2--;
                else pos2 = n - 1;
                if (!Hash[pos2]) t2++;
            }
            if (pos1 == pos2) { cnt++; printf("%3d", pos1 + 1); }
            else { cnt += 2; printf("%3d%3d", pos1 + 1, pos2 + 1); }
            cout << (cnt == n ? "\n" : ",");
            Hash[pos1] = Hash[pos2] = 1;
        }
    }
    return 0;
}

你可能感兴趣的:(加入题解目录题解,哈希算法,算法,c语言)