Football
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2801   Accepted: 1428

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
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>
using namespace std; const int maxn = 200;
const double eps = 0.0001;
struct tree{
int l , r;
double win[maxn];
}a[4*maxn];
double P[maxn][maxn];
int N[10] = {1 , 2 , 4 , 8 , 16 , 32 , 64 , 128 , 256 , 512};
int n; void initial(){
for(int i = 0; i < 4*maxn; i++){
for(int j = 0; j < maxn; j++){
a[i].win[j] = 0.0;
}
}
} void build(int l , int r , int k){
a[k].l = l;
a[k].r = r;
if(l == r){
a[k].win[l] = 1.0;
}else{
int mid = (l+r)/2;
build(l , mid , 2*k);
build(mid+1 , r , 2*k+1);
int i = l;
while(i <= mid){
for(int j = mid+1; j <= r; j++){
a[k].win[i] += a[2*k].win[i]*a[2*k+1].win[j]*P[i][j];
}
i++;
}
while(i <= r){
for(int j = l; j <= mid; j++){
a[k].win[i] += a[2*k].win[j]*a[2*k+1].win[i]*P[i][j];
}
i++;
}
}
} void readcase(){
for(int i = 0; i < N[n]; i++){
for(int j = 0; j < N[n]; j++){
scanf("%lf" , &P[i][j]);
}
}
} void computing(){
build(0 , N[n]-1 , 1);
int ans = 0;
for(int i = 1; i < N[n]; i++){
if(a[1].win[i] - a[1].win[ans] > eps){
ans = i;
}
}
printf("%d\n" , ans+1);
} int main(){
while(scanf("%d" , &n) && n != -1){
initial();
readcase();
computing();
}
return 0;
}

poj 3071 Football(线段树+概率)的更多相关文章

  1. POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)

    POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...

  2. Buy Tickets POJ - 2828 思维+线段树

    Buy Tickets POJ - 2828 思维+线段树 题意 是说有n个人买票,但是呢这n个人都会去插队,问最后的队列是什么情况.插队的输入是两个数,第一个是前面有多少人,第二个是这个人的编号,最 ...

  3. poj 3264(线段树)

    http://poj.org/problem?id=3264 初学线段可以做的水题,也是线段树的基础运用.也是我的第一个线段树的题. 题意:在区间范围内的最大值减去最小值 思路:线段树记录下每个区间内 ...

  4. poj City Horizon (线段树+二分离散)

    http://poj.org/problem?id=3277 City Horizon Time Limit: 2000MS   Memory Limit: 65536K Total Submissi ...

  5. poj 3667 Hotel (线段树)

    http://poj.org/problem?id=3667 Hotel Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 94 ...

  6. LOJ#3043.【ZJOI2019】 线段树 线段树,概率期望

    原文链接www.cnblogs.com/zhouzhendong/p/ZJOI2019Day1T2.html 前言 在LOJ交了一下我的代码,发现它比选手机快将近 4 倍. 题解 对于线段树上每一个节 ...

  7. CodeForces - 138C: Mushroom Gnomes - 2 (线段树&概率&排序)

    One day Natalia was walking in the woods when she met a little mushroom gnome. The gnome told her th ...

  8. POJ 1177 Picture(线段树 扫描线 离散化 求矩形并面积)

    题目原网址:http://poj.org/problem?id=1177 题目中文翻译: 解题思路: 总体思路: 1.沿X轴离散化建树 2.按Y值从小到大排序平行与X轴的边,然后顺序处理 如果遇到矩形 ...

  9. POJ 2299 Ultra-QuickSort(线段树+离散化)

    题目地址:POJ 2299 这题以前用归并排序做过.线段树加上离散化也能够做.一般线段树的话会超时. 这题的数字最大到10^10次方,显然太大,可是能够利用下标,下标总共仅仅有50w.能够从数字大的開 ...

随机推荐

  1. OCP-1Z0-051-题目解析-第26题

    26. Which is the valid CREATE TABLE statement? A. CREATE TABLE  emp9$#  (emp_no NUMBER (4));  B. CRE ...

  2. Floodlight中 处理packetin消息的顺序(2)

         前面通过阅读代码知道了怎样推断各个模块处理某个消息的先后顺序.那么内部是怎样实现的呢?      每当一个模块表示对一个消息感兴趣的时候,就会调用IFloodlightProviderSer ...

  3. ios代理的使用,正向传值,逆向传值

    #import <UIKit/UIKit.h> #import "SubViewController.h" @interface ViewController : UI ...

  4. Image-Loader LruMemoryCache

    这段时间在研究Universal-Image-Loader 这个图片处理开源框架,这里主要分析一下它的LRU(Least Resently Used,最近最少使用算法)内存缓存的实现. 在UIL它提供 ...

  5. js---17继承中方法属性的重写

    function F(){}; var f = new F(); f.name = "cf"; f.hasOwnProperty("name");//true ...

  6. Vectorized implementation

    Vectorization Vectorization refers to a powerful way to speed up your algorithms. Numerical computin ...

  7. 1>LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏

    解决方法如下:项目\属性\配置属性\清单工具\输入和输出\嵌入清单:原来是“是”,改成“否”. 终极解决方案:VS2010在经历一些更新后,建立Win32 Console Project时会出“err ...

  8. vue 实例的生命周期

      Vue把整个生命周期划分为创建.挂载.更新.销毁等阶段,每个阶段都会给一些"钩子"让我们来做一些我们想实现的动作. 分为以下几个阶段 1.beforeCreate   此阶段为 ...

  9. spring三大框架整合

        Spring概述 Spring介绍 Spring它是一个一站式的分层轻量级框架. Spring体系结构 1.      core container a)        beans与core ...

  10. 各种join一目了然: join 、inner join、left join 、right join、full join

    各种join一幅图一目了然 一下每幅图都是指: A * join B on A.id = B.in 这个帖子也非常形象.比較好:http://www.phpddt.com/db/inner_join- ...