24h購物| | PChome| 登入
2012-04-17 17:25:41| 人氣1,100| 回應0 | 上一篇 | 下一篇

[UVA] 11222 - Only I did it!

推薦 0 收藏 0 轉貼0 訂閱站台

D. Only I did it!

Time limit: 1s

Once upon a time, in the land of Ceeplenty, lived 3 friends that liked to solve problems. They used internet engines to look for problems and they often tried to solve the problems that none of the other 2 had solved. They once met you and you managed to convince them that you were better at problem solving. So they asked you to write a program that tells which of the 3 friends solved more problems that none of the other 2 have solved.

Input

The first line of input gives the number of cases, T (1 ≤ T ≤ 20). T test cases follow. Each test case is composed of three lines corresponding to the problems solved by the first, second and third friend, respectively. Each of these lines has an integer S (0 ≤ S ≤ 1000) followed by the list of S solved problems. A solved problem is identified uniquely by a positive integer smaller or equal than 10000.

Output

The output is comprised a line identifying the test case with the string Case #C: (where C is the number of the current test case). Then print another line with the number of the friend (1, 2 or 3) asked in the description followed by the number of problems that he solved but none of the other 2 did, followed by the sorted list of these problems in one line. When there is a tie, print one such line for each tied friend, sorted by the number of the friend.

Sample input

4
3 1 2 3
4 4 5 6 7
5 8 9 10 11 12
2 1 5
2 2 3
3 2 3 1
6 400 401 402 403 404 405
2 101 100
7 400 401 402 403 404 405 406
1 1
1 2
1 3

Sample output

Case #1:
3 5 8 9 10 11 12
Case #2:
1 1 5
Case #3:
2 2 100 101
Case #4:
1 1 1
2 1 2
3 1 3



#include <stdio.h>
#include <algorithm>
using namespace std;

int main() {
int t, Case = 0;
int i, j;
scanf("%d", &t);
while(t--) {
printf("Case #%d:\n", ++Case);
int A[3], B[3][1000];
int mark[10001] = {};
for(i = 0; i < 3; i++) {
scanf("%d", &A[i]);
for(j = 0; j < A[i]; j++) {
scanf("%d", &B[i][j]);
mark[B[i][j]]++;
}
sort(B[i], B[i]+A[i]);
}
int max = 0, solve[3];
for(i = 0; i < 3; i++) {
int tmp = 0;
for(j = 0; j < A[i]; j++)
if(mark[B[i][j]] == 1)
tmp++;
if(tmp > max)
max = tmp;
solve[i] = tmp;
}
for(i = 0; i < 3; i++) {
if(solve[i] == max) {
printf("%d %d", i+1, solve[i]);
for(j = 0; j < A[i]; j++)
if(mark[B[i][j]] == 1)
printf(" %d", B[i][j]);
puts("");
}
}
}
return 0;
}

台長: Morris
人氣(1,100) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][AC自動機] 10679 - I Love Strings!!
此分類上一篇:[UVA] 544 - Heavy Cargo

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文