Football(POJ3071)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 3469 | Accepted: 1782 |
Description
Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2n. In each round of the tournament, all teams still in the tournament are placed in a list in order of increasing index. Then, the first team in the list plays the second team, the third team plays the fourth team, etc. The winners of these matches advance to the next round, and the losers are eliminated. After n rounds, only one team remains undefeated; this team is declared the winner.
Given a matrix P = [pij] such that pij is the probability that team i will beat team j in a match determine which team is most likely to win the tournament.
Input
The input test file will contain multiple test cases. Each test case will begin with a single line containing n (1 ≤ n ≤ 7). The next 2n lines each contain 2n values; here, the jth value on the ith line represents pij. The matrix P will satisfy the constraints that pij = 1.0 − pji for all i ≠ j, and pii = 0.0 for all i. The end-of-file is denoted by a single line containing the number −1. Note that each of the matrix entries in this problem is given as a floating-point value. To avoid precision problems, make sure that you use either the double data type instead offloat.
Output
The output file should contain a single line for each test case indicating the number of the team most likely to win. To prevent floating-point precision issues, it is guaranteed that the difference in win probability for the top two teams will be at least 0.01.
Sample Input
2
0.0 0.1 0.2 0.3
0.9 0.0 0.4 0.5
0.8 0.6 0.0 0.6
0.7 0.5 0.4 0.0
-1
Sample Output
2
Hint
In the test case above, teams 1 and 2 and teams 3 and 4 play against each other in the first round; the winners of each match then play to determine the winner of the tournament. The probability that team 2 wins the tournament in this case is:
| P(2 wins) | = P(2 beats 1)P(3 beats 4)P(2 beats 3) + P(2 beats 1)P(4 beats 3)P(2 beats 4) = p21p34p23 + p21p43p24 = 0.9 · 0.6 · 0.4 + 0.9 · 0.4 · 0.5 = 0.396. |
The next most likely team to win is team 3, with a 0.372 probability of winning the tournament.
Source
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define N 130
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
using namespace std;
#define MAXN 2
#define ll double
double p[N][N], win[][N]; int main()
{
int n;
while(~scanf("%d", &n) && n != -)
{
for(int i = ; i <= ( << n); i++)
for(int j = ; j <= ( << n); j++)
scanf("%lf", &p[i][j]);
for(int i = ; i <= ( << n); i++) win[][i] = 1.0; double t;
for(int i = ; i <= n; i++)
for(int j = ; j <= ( << n); j++) {
int k = (j - ) / ( << (i - ));
t = 0.0;
if(k % )
for(int q = (k - ) * ( << (i - )) + ; q <= k * ( << (i - )); q++)
t += win[i - ][j] * win[i - ][q] * p[j][q];
else
for(int q = (k + ) * ( << (i - )) + ; q <= (k + ) * ( << (i - )); q++)
t += win[i - ][j] * win[i - ][q] * p[j][q];
win[i][j] = t;
} double maxn = -1.0;
int winner = ;
for(int i = ; i <= ( << n); i++)
if(win[n][i] > maxn) maxn = win[n][i], winner = i; printf("%d\n", winner); }
return ;
}
Football(POJ3071)的更多相关文章
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- poj3071 Football(概率dp)
poj3071 Football 题意:有2^n支球队比赛,每次和相邻的球队踢,两两淘汰,给定任意两支球队相互踢赢的概率,求最后哪只球队最可能夺冠. 我们可以十分显然(大雾)地列出转移方程(设$f[ ...
- 我的MYSQL学习心得(六) 函数
我的MYSQL学习心得(六) 函数 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类 ...
- java面试题及答案(转载)
JAVA相关基础知识1.面向对象的特征有哪些方面 1.抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时 ...
- 使用 PHP 过滤器(Filter)进行严格表单验证
PHP 过滤器(Filter)用于验证和过滤来自非安全来源的数据,比如用户的输入,使用过滤器扩展可以使数据过滤更轻松快捷.要求的 PHP 版本是 PHP 5 >= 5.2.0,PHP 7 和 F ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- Java面试题大全(四)
JAVA代码查错 1. abstract class Name { private String name; public abstract boolean isStupidName(String n ...
- (转)MySQL联表查询
资料源于网络 一.内联结.外联结.左联结.右联结的含义及区别在SQL标准中规划的(Join)联结大致分为下面四种:1.内联结:将两个表中存在联结关系的字段符合联结关系的那些记录形成记录集的联结.2 ...
- JfreeChart使用(转载)
http://www.cnblogs.com/xingyun/ http://www.huosen.net/archives/156.html(此篇除了struts2外,还介绍了servlet下Jfr ...
随机推荐
- 06_在web项目中集成Spring
在web项目中集成Spring 一.使用Servlet进行集成测试 1.直接在Servlet 加载Spring 配置文件 ApplicationContext applicationContext = ...
- [Effective Java]第五章 泛型
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- eclipse 实用快捷键
Ctrl+E: 弹出输入窗口,可快速返回想返回的目标界面 Ctrl+Shift+O: 快速import包 Ctrl+O:显示类中方法和属性的大纲 Ctrl+1 快速修复 Ctrl+Alt+↓ 复制当前 ...
- s表达式和json表达式
s表达式 + 1 2 3普通表达式 1+2+3json表达式{ +:[1, 2, 3]}优点,一个运算符,无限个参数 s表达式 * (+ 1 2) 3普通表达式 1+(2*3)json表达式{ *:[ ...
- Http协议简单学习笔记
HTTP是hypertext transfer protocol(超文本传输协议)的简写,它是TCP/IP协议的一个应用层协议,用于定义WEB浏览器与WEB服务器之间交换数据的过程. 在HTTP1.0 ...
- iOS - Swift Array 数组
前言 public struct Array<Element> : CollectionType, MutableCollectionType, _DestructorSafeContai ...
- iOS - Swift NSRect 位置和尺寸
前言 结构体,这个结构体用来表示事物的坐标点和宽高度. public typealias NSRect = CGRect public struct CGRect { public var origi ...
- STRUTS2 嵌套循环
<!--begin 类目循环 --> <s:iterator value="categories" id='i' begin="0" step ...
- 理解odbc
1.解决什么样的问题?不同的数据库产品,具有不同的特性,也就是方言.因此应用程序针对不同的数据库产品,编写不同的代码.如果换了一个数据库产品,还需要重新编写数据库交互部分,不具备扩展和移植.odbc对 ...
- (八)C语言结构体和指针
指针也可以指向一个结构体变量.定义的一般形式为: struct 结构体名 *变量名; 前面已经定义了一个结构体 stu: struct stu { char *name; int num; char ...