2013年8月26日

UVa 144 - Student Grants

#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;

struct Student {
  int id, need;
};

int main() {
  int n, k;
  while (scanf("%d%d", &n, &k) && n) {
    queue<Student> q;
    for (int i = 1; i <= n; i++) {
      q.push((Student){i, 40});
    }
    while (!q.empty()) {
      for (int i = 1; i <= k; i++) {
        int remain = i;
        while (remain && !q.empty()) {
          Student now = q.front();
          q.pop();
          if (now.need > remain) {
            now.need -= remain;
            remain = 0;
            q.push(now);
          } else {
            remain -= now.need;
            printf("%3d", now.id);
          }
        }
      }
    }
    puts("");
  }
  return 0;
}

沒有留言:

張貼留言