URAL 1868 Prediction&n…

http://acm.timus.ru/problem.aspx?space=1&num=1868
G - Prediction Contest
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

At the ICPC World Finals, four sets of gold medals, four sets of silver medals, and four sets of bronze medals are awarded; thus, top twelve teams win medals.
There were few days left before the World Finals in Orlando. Veterans of collegiate programming contests from Ural State University were hotly debating chances of the teams for medals at the forthcoming contest. Vadik suggested that every person who wanted to make a prediction for the results of the finals should pool five dollars and state several guesses of the form “The team of university  X  will win a medal of type  Y.” The veterans who made the maximum number of true guesses would share the pooled money between them.
But the veterans refused saying that the results of the finals are always very difficult to predict and nobody wanted to lose five dollars. Then Vadik changed the conditions of the prediction contest. He said that the participants didn't have to pay, but everybody who made the maximum number of true predictions would receive five dollars from Vadik. The veterans agreed to these conditions, and each of them stated several predictions about which team would win which medal.
Given the result of the World Finals and all the predictions made, find the amount of money that Vadik had to pay to the winners of the competition.

Input

In the first twelve lines you are given the names of the universities winning the medals of the World Finals. The universities are listed in the order from the first place to the twelfth place.
In the following line you are given the number  n  of participants of the prediction contest (1 ≤  n  ≤ 100). Then go  n  blocks containing the veterans' predictions. The  ith block starts with the number of predictions  k i  made by the  ith participant. The predictions are given in the following  k i  lines, each prediction has the form   . Here, is the word “gold”, “silver”, or “bronze”. The predictions of each participant are consistent: no university can win more than one medal and the total number of medals of each kind is at most four.
The names of the universities consist of uppercase and lowercase English letters, underscore characters, dots, and commas. The length of each name is in the range from one to thirty symbols.

Output

Output the amount of money that Vadik paid according to the result of the prediction contest. If more than one participant made the maximum number of true predictions, Vadik paid five dollars to each of them.

Sample Input

input output
Zhejiang_U
U_of_Michigan_at_Ann_Arbor
Tsinghua_U
St._Petersburg_SU
Nizhny_Novgorod_SU
Saratov_SU
Friedrich_Alexander_U
Donetsk_National_U
Jagiellonian_U_in_Krakow
Moscow_SU
Ural_SU
U_of_Waterloo
3
6
Moscow_SU : gold
St._Petersburg_SU_of_ITMO : gold
Warsaw_U : gold
Tsinghua_U : gold
Nizhny_Novgorod_SU : silver
Saratov_SU : silver
6
Warsaw_U : gold
Saratov_SU : gold
Tsinghua_U : gold
Donetsk_National_U : silver
St._Petersburg_SU_of_ITMO : silver
Ural_SU : bronze
6
Zhejiang_U : gold
Tsinghua_U : gold
Shanghai_Jiao_Tong_U : gold
Fudan_U : gold
Moscow_SU : silver
Nizhny_Novgorod_SU : silver
15
题意:每个人可以猜一组数据求猜中的最大可能。
代码1:(ac)
 
        
 
        
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#pragma warning(disable: 4786)

using namespace std;

map<string, string> m;
int main() {
        string str;
        for (int i = 1; i <= 4; i++) {
                cin >> str;
                //scanf("%s",str);
                m[str] = "gold";
        }
        for (int i = 1; i <= 4; i++) {
                cin >> str;
                // scanf("%s",str);
                m[str] = "silver";
        }
        for (int i = 1; i <= 4; i++) {
                cin >> str;
                //scanf("%s",str);
                m[str] = "bronze";
        }
        int n, sum = 0, qt = 0;
        scanf("%d", &n);
        while (n--) {
                string s1, s2, s3;
                int t;
                scanf("%d", &t);
                int cnt = 0;
                for (int i = 0; i < t; i++) {
                        cin >> s1 >> s3 >> s2;
                        //scanf(" : ");
                        //cin>>s1;
                        //scanf("%s : %s",s1,s2);
                        if (m[s1] == s2) {
                                cnt++;
                        }
                }
                if (sum < cnt) {
                        sum = cnt;
                        qt = 1;
                } else if (sum == cnt) {
                        qt++;
                }
        }
        printf("%d\n", qt * 5);
        return 0;
}


代码2:(wa),不知道为什么
#include 
#include
#include
#include
using namespace std;
int sum[1010];
char s[110][110], s1[110], s2[110];

int cmp(const void *a, const void *b) {
        return *(int *) a <= *(int *) b;
}

int main()
{
    memset(s,0,sizeof(s));
    while(scanf("%s",s[0])!=EOF)
    {

        for (int i = 1; i <</span> 12; i++) {
            scanf("%s", s[i]);
        }
        int n;
        scanf("%d", &n);
        //int sum[1010];
        memset(sum, 0, sizeof(sum));
        memset(s1,0,sizeof(s1));
        memset(s2,0,sizeof(s2));
        for (int k = 0; k <</span> n; k++) {
            int m;
            scanf("%d", &m);
            //getchar();
            for (int i = 0; i <</span> m; i++) {
                scanf("%s : %s", s1, s2);
                for (int j = 0; j <</span> 12; j++) {
                    if (strcmp(s1, s[j]) == 0 && j <= 3 && j >= 0) {
                        if (strcmp(s2, "gold") == 0) {
                            sum[k]++;
                            break;
                        }
                    } else if (strcmp(s1, s[j]) == 0 && j >= 4 && j <= 7) {
                        if (strcmp(s2, "silver") == 0) {
                            sum[k]++;
                            break;
                        }
                    }
                    if (strcmp(s1, s[j]) == 0 && j >= 8 && j <</span> 12) {
                        if (strcmp(s2, "bronze") == 0) {
                            sum[k]++;
                            break;
                        }
                    }
                }
            }
        }
        sort(sum,sum+n);
       // qsort(sum, n, sizeof(int), cmp);
        int count = 1;
        for (int i = n-1; i >=1 ; i--) {
            if (sum[i] == sum[i - 1]) {
                count++;
            }
        }
        if (count == 1)
            printf("%d\n", sum[n-1]);
        else {
            printf("%d\n", count * 5);
        }
        memset(s,0,sizeof(s));
    }
        return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值