UVA11348 Exhibition【序列】

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值