Some friends have the same hobby, they are collecting stamps. Once upon a time they decided to make an exhibition. Exhibition brought them some money and now they do not know how to divide their income. They decided to divide their money according this rule: “The percent of whole income that i-th friend will get is equal to the part of his unique stamp’s type.”
The stamp type is called unique if and only if this type of stamps of owned only by one person.
Input
The first line contains integer K (0 < K ≤ 100), it is number of tests. Each test case is described by positive integer N (0 < N ≤ 50), it‘s the number of friends. Next goes N lines with integers. Each line corresponds one friend stamp collection. The first integer on the line is M — the number of stamps owned by a person (0 < M ≤ 50). Next goes M integers A (0 ≤ A ≤ 10000) — types of stams.
Output
For each test case out line formatter like this: ‘Case i: a1% a2% a3% . . . an%’. Where i is a test number, and ai percent of income that goes to i-th friend.
Sample Input
1
3
3 1 2 3
2 4 5
3 4 2 6
Sample Output
Case 1: 50.000000% 25.000000% 25.000000%
问题链接:UVA11348 Exhibition
问题简述:(略)
问题分析:
先给代码暂时不解释 。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA11348 Exhibition */
#include <bits/stdc++.h>
using namespace std;
const int M = 50;
double friends[M + 1];
const int A = 10000;
int stamps[A + 1];
int main()
{
int t, caseno = 0, n, m, type;
scanf("%d", &t);
while(t--) {
memset(stamps, 0, sizeof(stamps));
memset(friends, 0, sizeof(friends));
int unique_stamps = 0;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", &m);
for(int j = 0; j < m; j++) {
scanf("%d", &type);
if(stamps[type] == 0) {
stamps[type] = i;
friends[i]++;
unique_stamps++;
} else if(stamps[type] > 0 && stamps[type] != i) {
friends[stamps[type]]--;
stamps[type] = -1;
unique_stamps--;
}
}
}
printf("Case %d: ", ++caseno);
if(unique_stamps > 0) {
for(int i = 1; i < n; i++)
printf("%.6f%% ", (double)friends[i] / unique_stamps * 100);
printf("%.6f%%", (double)friends[n] / unique_stamps * 100);
}
printf("\n");
}
return 0;
}