UVA542 POJ2261 ZOJ1950 France ‘98概率

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA542 POJ2261 ZOJ1950 France ‘98概率相关的知识,希望对你有一定的参考价值。

France '98
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1318 Accepted: 791

Description

Today the first round of the Soccer World Championship in France is coming to an end. 16 countries are remaining now, among which the winner is determined by the following tournament:


1 Brazil -----+
+-- ? --+
2 Chile ------+ |
+-- ? --+
3 Nigeria ----+ | |
+-- ? --+ |
4 Denmark ----+ |
+-- ? --+
5 Holland ----+ | |
+-- ? --+ | |
6 Yugoslavia -+ | | |
+-- ? --+ |
7 Argentina --+ | |
+-- ? --+ |
8 England ----+ |
+-- World Champion
9 Italy ------+ |
+-- ? --+ |
10 Norway -----+ | |
+-- ? --+ |
11 France -----+ | | |
+-- ? --+ | |
12 Paraguay ---+ | |
+-- ? --+
13 Germany ----+ |
+-- ? --+ |
14 Mexico -----+ | |
+-- ? --+
15 Romania ----+ |
+-- ? --+
16 Croatia ----+

For each possible match A vs. B between these 16 nations, you are given the probability that team A wins against B. This (together with the tournament mode displayed above) is sufficient to compute the probability that a given nation wins the World Cup. For example, if Germany wins against Mexico with 80%, Romania against Croatia with 60%, Germany against Romania with 70% and Germany against Croatia with 90%, then the probability that Germany reaches the semi-finals is 80% * (70% * 60% + 90% * 40%) = 62.4%.
Your task is to write a program that computes the chances of the 16 nations to become the World Champion '98.

Input

The input will contain just one test case.
The first 16 lines of the input file give the names of the 16 countries, from top to bottom according to the picture given above.
Next, there will follow a 16 x 16 integer matrix P where element pijgives the probability in percent that country #i defeats country #j in a direct match. Country #i means the i-th country from top to bottom given in the list of countries. In the picture above Brazil is #1 and Germany is #13, so p1,13=55 would mean that in a match between Brazil and Germany, Brazil wins with a probability of 55%.
Note that matches may not end with a draw, i.e. pij + pji = 100 for all i,j.

Output

Output 16 lines of the form “XXXXXXXXXX p=Y.YY%”, where XXXXXXXXXX is the country’s name, left-justified in a field of 10 characters, and Y.YY is their chance in percent to win the cup, written to two decimal places. Use the same order of countries like in the input file.
Sample Input

Brazil
Chile
Nigeria
Denmark
Holland
Yugoslavia
Argentina
England
Italy
Norway
France
Paraguay
Germany
Mexico
Romania
Croatia
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
35 50 35 45 40 35 35 50 30 40 25 40 25 40 35 35
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
40 55 40 50 45 40 40 55 35 45 30 45 30 45 40 40
45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
35 50 35 45 40 35 35 50 30 40 25 40 25 40 35 35
55 70 55 65 60 55 55 70 50 60 45 60 45 60 55 55
45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45
60 75 60 70 65 60 60 75 55 65 50 65 50 65 60 60
45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45
60 75 60 70 65 60 60 75 55 65 50 65 50 65 60 60
45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50

Sample Output

Brazil p=8.54%
Chile p=1.60%
Nigeria p=8.06%
Denmark p=2.79%
Holland p=4.51%
Yugoslavia p=7.50%
Argentina p=8.38%
England p=1.56%
Italy p=9.05%
Norway p=3.23%
France p=13.72%
Paraguay p=3.09%
Germany p=13.79%
Mexico p=3.11%
Romania p=5.53%
Croatia p=5.53%

Source

Ulm Local 1998

问题链接UVA542 POJ2261 ZOJ1950 France '98
问题简述:(略)
问题分析:概率问题,不解释。解题代码来自仙客传奇团队。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA542 POJ2261 ZOJ1950 France '98 */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

const int N = 16;
double p[N + 1][N + 1], ans[N + 1], t[N + 1];
char name[N + 1][N + 1];

int main()

    for (int i = 1; i <= N; i++)
        ans[i] = 1.0;

    for (int i = 1; i <= N; i++)
        scanf("%s", name[i]);
    for (int i = 1;i <= N; i++)
        for (int j = 1; j <= N; j++) 
            scanf("%lf", &p[i][j]);
            p[i][j] /= 100;
        

    int group, tmp, g, s;
    for (int i = 1; i <= 4; i++) 
        group = pow(2, i);
        tmp = group / 2;

        for (int j = 1; j <= N; j++) 
            g = (j - 1) / group;

            if ((j - 1) % group < tmp)
                s = g * group + tmp;
            else
                s =g * group;

            double c = 0;
            for (int k = 1; k <= tmp; k++)
                c += ans[j] * p[j][k + s] * ans[k + s];
            t[j] = c;
        

        memcpy(ans, t, sizeof(ans));
    

    for (int i = 1; i <= N; i++)
        printf("%-10s p=%.2f%%\\n", name[i], ans[i] * 100);

    return 0;

以上是关于UVA542 POJ2261 ZOJ1950 France ‘98概率的主要内容,如果未能解决你的问题,请参考以下文章

UVA10670 POJ1907 ZOJ2372 Work Reduction贪心

UVA10081 POJ2537 ZOJ1883 Tight WordsDP

UVA10277 POJ2646 ZOJ1856 Boastin‘ Red Socks数学

POJ2689 ZOJ1842 UVA10140 Prime Distance筛选法

POJ2351 ZOJ1916 UVA10371 Time Zones时区计算

UVA10202 POJ2466 ZOJ1895 Pairsumonious Numbers算术计算