2013年8月8日

UVa 11222 - Only I did it!

#include <cstdio>

int main() {
  int T, C = 1;
  scanf("%d", &T);
  while (T--) {
    bool solved[3][100001] = {};
    for (int i = 0; i < 3; i++) {
      int num;
      scanf("%d", &num);
      while (num--) {
        int id;
        scanf("%d", &id);
        solved[i][id] = true;
      }
    }
    int unique[3] = {}, max = 0;
    bool ans[3][10001] = {};
    for (int i = 0; i < 10001; i++) {
      unique[0] += solved[0][i] && !solved[1][i] && !solved[2][i];
      ans[0][i] = solved[0][i] && !solved[1][i] && !solved[2][i];
      unique[1] += !solved[0][i] && solved[1][i] && !solved[2][i];
      ans[1][i] = !solved[0][i] && solved[1][i] && !solved[2][i]; 
      unique[2] += !solved[0][i] && !solved[1][i] && solved[2][i];
      ans[2][i] = !solved[0][i] && !solved[1][i] && solved[2][i];
    }
    for (int i = 0; i < 3; i++) {
      max = unique[i] > max ? unique[i] : max;
    }
    printf("Case #%d:\n", C++);
    for (int i = 0; i < 3; i++) {
      if (unique[i] == max) {
        printf("%d %d", i + 1, max);
        for (int j = 0; j < 10001; j++) {
          if (ans[i][j]) {
            printf(" %d", j);
          }
        }
        puts("");
      }
    }
  }
  return 0;
}

沒有留言:

張貼留言