Football
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 2882 | Accepted: 1466 |
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 nrounds, 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 representspij. 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 of float.
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.
#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
const int ms=;
double p[ms][ms];
double dp[ms][];
int main()
{
int n,i,j;
while(scanf("%d",&n),n!=-)
{
int m=(<<n);
for(i=;i<m;i++)
{
for(j=;j<m;j++)
scanf("%lf",&p[i][j]);
dp[i][]=;
}
int ans;
for(i=;i<n;i++)
{
ans=;
for(j=;j<m;j++)
{
double sum=;
for(int k=(<<i);k<(<<(i+));k++)
{
sum+=dp[k^j][i]*p[j][k^j];
}
dp[j][i+]=dp[j][i]*sum;
if(dp[j][i+]>dp[ans][i+])
ans=j;
}
}
printf("%d\n",ans+);
}
return ;
}
Football的更多相关文章
- POJ 3071 Football
很久以前就见过的...最基本的概率DP...除法配合位运算可以很容易的判断下一场要和谁比. from——Dinic算法 Football Time ...
- Football Foundation (FOFO) TOJ 2556
The football foundation (FOFO) has been researching on soccer; they created a set of sensors to desc ...
- 17111 Football team
时间限制:1000MS 内存限制:65535K 提交次数:0 通过次数:0 题型: 编程题 语言: C++;C Description As every one known, a footbal ...
- CodeForces 432B Football Kit
Football Kit Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Subm ...
- Football(POJ3071)
Football Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3469 Accepted: 1782 Descript ...
- 16年大连网络赛 1006 Football Games
题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?cid=725&pid=1006 Football Games Time ...
- 三分--Football Goal(面积最大)
B - Football Goal Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
- HDU5873:Football Games
题目链接: Football Games 分析: 先将分数排序,然后 设当前队编号为p,设个指针为p+1,然后p>1,每次p-=2,指针右移一位p==1,指针指向的队-=1p==0,从指针开始到 ...
- Codeforces Gym 100425H H - Football Bets 构造
H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
随机推荐
- SQL Server 执行计划
当一个查询被提交时,发生了什么? 向SQL Server提交一个查询时,sever上的许多进程会在这个查询上开始工作. 这些进程的目标就是管理这个系统,使得这个查询可以选择,插入,更新,删除数据. 每 ...
- Nginx 工作原理和优化、漏洞
1. Nginx的模块与工作原理 Nginx由内核和模块组成,其中,内核的设计非常微小和简洁,完成的工作也非常简单,仅仅通过查找配置文件将客户端请求映射到一个location block(locat ...
- sizeof 字符数组
比较 #include <stdio.h> #include <string.h> int main(int argc, const char *argv[]) { char ...
- 一些常用的IOS开发网站
开发教程: 即便过了入门阶段,还是要经常看看一些不错的实例教程.1.http://mobile.tutsplus.com/category/tutorials/iphone/ 比较新的一个网站,以前没 ...
- POJ 1062 昂贵的聘礼 (最短路)
昂贵的聘礼 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/M Description 年轻的探险家来到了一个印第安部落里.在那里 ...
- PID参数整定快速入门(调节器参数整定方法)
PID调节器参数整定方法很多,常见的工程整定方法有临界比例度法.衰减曲线法和经验法.云润仪表以图文形式分别介绍调节器参数整定方法. 临界比例度法一个调节系统,在阶跃干扰作用下,出现既不发散也不衰减的等 ...
- UIImageView旋转任意角度
-(UIImageView *) makeRotation:(UIImageView *)image speedX:(float)X speedY:(float)Y { // 头文件中需要定义 ...
- 新网注册域名如何转向其他(如花生壳)DNS(不会报错,已经转入成功)
最近在玩域名,发现相比较来说,新网的域名注册费用相对廉价好多. 但是我以前是用花生壳的,用惯了花生壳,就觉得新网的域名管理界面很不适应,并不是新网的不好,而是习惯了花生壳. 那么如何将新网注册的域名D ...
- [转]eclipse中使用maven插件的时候,运行run as maven build的时候报错
转至:http://fxb4632242.iteye.com/blog/2193945 -Dmaven.multiModuleProjectDirectory system propery is no ...
- JqueryMobile- 搭建主模板
最近公司要开发手机端的,可是我没学过安卓,然后用HTML5+JQUERYMOBILE也可以做这些手机端的程序,做成个网页,发到网上,免强也行,于是开始了我JQUERYMOBILE的学习. 先放一下主模 ...