542 - France '98 (概率 dp)
来源:互联网 发布:可用端口号范围 编辑:程序博客网 时间:2024/06/06 01:29
France '98
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 file 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 16 integer matrix P where element pij gives 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
BrazilChileNigeriaDenmarkHollandYugoslaviaArgentinaEnglandItalyNorwayFranceParaguayGermanyMexicoRomaniaCroatia50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 5035 50 35 45 40 35 35 50 30 40 25 40 25 40 35 3550 65 50 60 55 50 50 65 45 55 40 55 40 55 50 5040 55 40 50 45 40 40 55 35 45 30 45 30 45 40 4045 60 45 55 50 45 45 60 40 50 35 50 35 50 45 4550 65 50 60 55 50 50 65 45 55 40 55 40 55 50 5050 65 50 60 55 50 50 65 45 55 40 55 40 55 50 5035 50 35 45 40 35 35 50 30 40 25 40 25 40 35 3555 70 55 65 60 55 55 70 50 60 45 60 45 60 55 5545 60 45 55 50 45 45 60 40 50 35 50 35 50 45 4560 75 60 70 65 60 60 75 55 65 50 65 50 65 60 6045 60 45 55 50 45 45 60 40 50 35 50 35 50 45 4560 75 60 70 65 60 60 75 55 65 50 65 50 65 60 6045 60 45 55 50 45 45 60 40 50 35 50 35 50 45 4550 65 50 60 55 50 50 65 45 55 40 55 40 55 50 5050 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%
题意:给定16只球队名字和i和j队比赛i队赢的概率。求每个球队得冠军概率
思路:dp[k][i]表示第i只球队在第k轮出线的概率。 那么可得方程dp[k][i] = dp[k - 1][i] * dp[k - 1][j] * (i赢j概率)。然后要多个判断,i和j要在同一组内并且i和j在上一场比赛中不是对手。
代码:
#include <stdio.h>#include <string.h>const int N = 20;const int d[5] = {1, 2, 4, 8, 16};int i, j, k;double v[N][N], dp[N - 10][N];char name[N][105];int main() {for (i = 1; i <= 16; i ++)gets(name[i]);for (i = 1; i <= 16; i ++)for (j = 1; j <= 16; j ++) {scanf("%lf", &v[i][j]);}for (i = 1; i <= 16; i ++)dp[0][i] = 100;for (k = 1; k <= 4; k ++) for (i = 1; i <= 16; i ++)for (j = 1; j <= 16; j ++) {if ((i - 1) / d[k] == (j - 1) / d[k] && (i - 1) / d[k - 1] != (j - 1) / d[k - 1])dp[k][i] += dp[k - 1][i] * dp[k - 1][j] * v[i][j] / 10000;}for (i = 1; i <= 16; i ++) {printf("%-10s p=%.2f%%\n", name[i], dp[4][i]);}return 0;}
- 542 - France '98 (概率 dp)
- France '98 - UVa 542 概率dp
- uva 542 - France '98(概率)
- UVA542 - France '98(dp)
- 542 - France '98
- UVA 542 France '98
- UVa:542 France '98
- uva 542 France '98
- France '98
- uva542 - France '98
- HRBEU/HEUOJ----1059 France '98
- 概率dp
- ##概率dp##
- 概率dp
- 概率dp
- 概率dp
- 概率dp
- 概率dp
- SNMP in NexnetaStor
- 【Python】基于PyUnit的自动化单元测试框架,PyUnitGUI
- 使用开源的Slidingmenu库 facebook、人人网、everynote、Google+
- 一个作业题---用python创建一个通讯录
- 编程之美 2.17 数组循环移位
- 542 - France '98 (概率 dp)
- 如何对时间进行简单加减运算
- 随便写点
- 逻辑题:题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单
- 初识windows编程之多线程
- NSString反向查找字符串
- iOS学习系列 - 扩展机制category与associative
- window和linux换行符处理
- MTU设置