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

  1. 2
  2. 0.0 0.1 0.2 0.3
  3. 0.9 0.0 0.4 0.5
  4. 0.8 0.6 0.0 0.6
  5. 0.7 0.5 0.4 0.0
  6. -1

Sample Output

  1. 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.

  1.  
  1.  
  1. 每一个节点记录这个区间每一个队赢的概率。
  1.  
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4. const int maxn = 200;
  5. const double eps = 0.0001;
  6. struct tree{
  7.     int l , r;
  8.     double win[maxn];
  9. }a[4*maxn];
  10. double P[maxn][maxn];
  11. int N[10] = {1 , 2 , 4 , 8 , 16 , 32 , 64 , 128 , 256 , 512};
  12. int n;
  13. void initial(){
  14.     for(int i = 0; i < 4*maxn; i++){
  15.         for(int j = 0; j < maxn; j++){
  16.             a[i].win[j] = 0.0;
  17.         }
  18.     }
  19. }
  20. void build(int l , int r , int k){
  21.     a[k].l = l;
  22.     a[k].r = r;
  23.     if(l == r){
  24.         a[k].win[l] = 1.0;
  25.     }else{
  26.         int mid = (l+r)/2;
  27.         build(l , mid , 2*k);
  28.         build(mid+1 , r , 2*k+1);
  29.         int i = l;
  30.         while(i <= mid){
  31.             for(int j = mid+1; j <= r; j++){
  32.                 a[k].win[i] += a[2*k].win[i]*a[2*k+1].win[j]*P[i][j];
  33.             }
  34.             i++;
  35.         }
  36.         while(i <= r){
  37.             for(int j = l; j <= mid; j++){
  38.                 a[k].win[i] += a[2*k].win[j]*a[2*k+1].win[i]*P[i][j];
  39.             }
  40.             i++;
  41.         }
  42.     }
  43. }
  44. void readcase(){
  45.     for(int i = 0; i < N[n]; i++){
  46.         for(int j = 0; j < N[n]; j++){
  47.             scanf("%lf" , &P[i][j]);
  48.         }
  49.     }
  50. }
  51. void computing(){
  52.     build(0 , N[n]-1 , 1);
  53.     int ans = 0;
  54.     for(int i = 1; i < N[n]; i++){
  55.         if(a[1].win[i] - a[1].win[ans] > eps){
  56.             ans = i;
  57.         }
  58.     }
  59.     printf("%d\n" , ans+1);
  60. }
  61. int main(){
  62.     while(scanf("%d" , &n) && n != -1){
  63.         initial();
  64.         readcase();
  65.         computing();
  66.     }
  67.     return 0;
  68. }
  69.  

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. php 图片局部打马赛克

    php 图片局部打马赛克 原理: 对图片中选定区域的每一像素,添加若干宽度及高度,生成矩型.而每一像素的矩型重叠在一起.就形成了马赛克效果. 本例使用GD库的imagecolorat获取像素颜色,使用 ...

  2. POJ 2185 正解 KMP

    题意: 思路: 把每一行压成一个数 求一下 KMP 把每一列压成一个数 求一下KMP 答案就是两个周期之积 网上的好多题解都是错的---------.. //By SiriusRen #include ...

  3. Elasticsearch之需要注意的问题(es和jdk版本)

    (1)在使用java代码操作es集群的时候 要保证本地使用的es的版本和集群上es的版本保持一致.  (2)保证集群中每个节点的JDK版本和es基本配置一致 这个很简单,不多说.  (3)es集群中j ...

  4. 完整性检查工具Nabou

    完整性检查工具Nabou 650) this.width=650;" onclick="window.open("http://blog.51cto.com/viewpi ...

  5. BZOJ1835: [ZJOI2010]base 基站选址(线段树优化Dp)

    Description 有N个村庄坐落在一条直线上,第i(i>1)个村庄距离第1个村庄的距离为Di.需要在这些村庄中建立不超过K个通讯基站,在第i个村庄建立基站的费用为Ci.如果在距离第i个村庄 ...

  6. Linux-PS1变量详解

    1.PS1 要修改linux终端命令行颜色,我们需要用到PS1,PS1是Linux终端用户的一个环境变量,用来说明命令行提示符的设置.在终端输入命令:#set,即可在输出中找到关于PS1的定义如下: ...

  7. 三分钟上手Highcharts简易甘特图

    根据业务需求,找到了这个很少使用的图形,话不多说,看看该如何使用.首先要引入支持文件:可根据链接下载. exporting.js:https://img.hcharts.cn/highcharts/m ...

  8. C++中的纯虚函数

    ---恢复内容开始--- 在C++中的一种函数申明被称之为:纯虚函数(pure virtual function).它的申明格式如下 class CShape { public: ; }; 在什么情况 ...

  9. 使用Spring实现MySQL读写分离(转)

    使用Spring实现MySQL读写分离 为什么要进行读写分离 大量的JavaWeb应用做的是IO密集型任务, 数据库的压力较大, 需要分流 大量的应用场景, 是读多写少, 数据库读取的压力更大 一个很 ...

  10. UICollectionView 集合视图 的使用

    直接上代码: // // RootViewController.m // // #import "RootViewController.h" #import "Colle ...