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. android Manifest.xml选项

    结构 继承关系 public final class Manifest extends Object java.lang.Object android.Manifest 内部类 class  Mani ...

  2. jquery的ajax总结

    jquery的ajax总结 一.总结 一句话总结:ajax函数中层级关系如下: 最底层的封装方式: $.ajax(); 第二层: .load(),$.get(), $.post() 最高层: $.ge ...

  3. 4. Brackets 前端编辑器试用

    转自:https://blog.csdn.net/wuji3390/article/details/71170579 Brackets编辑器介绍 "一个现代的,开源的,了解网页设计的编辑器& ...

  4. Vue项目自动转换 px 为 rem,高保真还原设计图

    技术栈 vue-cli:使用脚手架工具创建项目. postcss-pxtorem:转换px为rem的插件. 自动设置根节点html的font-size 因为rem单位是相对于根节点的字体大小的,所以通 ...

  5. 讲述ssh服务攻击案例及事件分析

    修改中 本文出自 "李晨光原创技术博客" 博客,谢绝转载!

  6. mvc4 视图中的form如何获取

    public ActionResult Index(FormCollection form)         {             var Name = form["字段名" ...

  7. chfn---改变finger命令显示的信息

    chfn命令   chfn命令用来改变finger命令显示的信息.这些信息都存放在/etc目录里的passwd文件里.若不指定任何选项,则chfn命令会进入问答式界面. 语法 chfn(选项)(参数) ...

  8. 一个一线城市的IT白领的生活成本:3万/年

    自从大学毕业,经济独立,就开始全面统计各种生活开支.仔细的去统计下,发现开销还是挺大的. 定理:开销越大,就意味着你每个月的收入必须越高. 三族鼎立节余族: 收入-开支 > 0月光族:收入-开支 ...

  9. [Express] Upload Files with Express

    In this lesson we create a new Express web server app for handling file uploads and persisting them ...

  10. iOS - 系统经常使用框架(framework)的简介

    系统框架(framework)的简介 ImageIO  - 该框架的接口可用于导入或导出图像数据及图像元数据 CoreTelephony  - 获取IMSI号,SIM卡背面的号码是SIM卡的电子串号, ...