Pong’s Birds(概率 模拟)
来源:互联网 发布:ubuntu网卡 编辑:程序博客网 时间:2024/05/29 15:54
Pong’s Birds
时间限制: 1 Sec 内存限制: 128 MB提交: 98 解决: 24
[提交][状态][讨论版]
题目描述
In order to train his birds, Pong is holding a competition for them. (He have birds, does he?) He have 2n birds,
so he want to hold elimination series. Literally, if n = 2 and he has 4 birds identified as 1,2,3,4, he would first hold competition for 1 and 2, 3 and 4, the one fails would be eliminated and then he holds competition for the winners.
According to his long observation, for each pair of birds he knows the probability to win for each bird, and he want to know the probability of each bird to be the final winner.
so he want to hold elimination series. Literally, if n = 2 and he has 4 birds identified as 1,2,3,4, he would first hold competition for 1 and 2, 3 and 4, the one fails would be eliminated and then he holds competition for the winners.
According to his long observation, for each pair of birds he knows the probability to win for each bird, and he want to know the probability of each bird to be the final winner.
输入
For the first row there is an integer T(T ≤ 100), which is the number of test cases.
For each case , first row is an integer n(1 ≤ n ≤ 7), for the next 2n rows , each row has 2n real numbers as the probability to win for the i-th when competed to j-th bird. It is promised that for each i, j p[i][j] + p[j][i] = 1 and p[i][i] = 0;
For each case , first row is an integer n(1 ≤ n ≤ 7), for the next 2n rows , each row has 2n real numbers as the probability to win for the i-th when competed to j-th bird. It is promised that for each i, j p[i][j] + p[j][i] = 1 and p[i][i] = 0;
输出
For each case you should output a line with 2n real numbers, which is the probability of i-th bird be the final winner. Rounded to 3 decimal places.
Make sure to output a space character after each number, to prevent the Presentation Error.
Make sure to output a space character after each number, to prevent the Presentation Error.
样例输入
110 0.50.5 0
样例输出
0.500 0.500
提示
2^n个鸟比赛,1和2,3和4...,然后每个赢的在和相邻的比,输的就被pass掉,然后求每个鸟成为winner的概率。
其实就是个模拟的过程,不过这里真正处理起来还是有点技巧和规律的。
这里有个奇偶互换的想法挺好的!!!
#include <bits/stdc++.h>using namespace std; const int MAXN = (1 << 7) + 5;double p[MAXN][MAXN];double dp[8][MAXN];//dp[i][j]表示第i轮j队伍出线概率 int main(){ int t; int n; int n2; int i, j, k; int grp; for (j = 0; j < MAXN; ++j) { dp[0][j] = 1; } scanf("%d", &t); while (t--) { scanf("%d", &n); n2 = 1 << n; for (i = 0; i < n2; ++i) { for (j = 0; j < n2; ++j) { scanf("%lf", &p[i][j]); } } for (i = 1; i <= n; ++i) { for (j = 0; j < n2; ++j) { grp = j / (1 << (i - 1)); grp ^= 1;//奇偶互换 dp[i][j] = 0; for (k = grp << (i - 1); k < ((grp + 1) << (i - 1)); ++k) { dp[i][j] += dp[i - 1][j] * dp[i - 1][k] * p[j][k]; } } } for (i = 0; i < n2 - 1; ++i) { printf("%.3lf ", dp[n][i]); } printf("%.3lf\n", dp[n][n2 - 1]); } return 0;}
0 0
- Pong’s Birds(概率 模拟)
- 石油大OJ 1023 问题 L: Pong’s Birds【概率Dp】
- 中石油多校联赛(最后一水) Pong’s Birds(dp)
- 石油大 2017年省赛前最后一水 1023: Pong’s Birds
- Birds in woods 概率DP
- 概率模拟
- hdu4662-枚举|搜索&模拟-Scaring the Birds
- 蓝桥杯-夺冠概率模拟(取随机数)
- (noip 模拟 allonsy)<概率+组合数学>
- ZOJ_3569_Dr. Zomboss's Revenge(概率期望)
- Robot's Task(模拟)
- Alena's Schedule(模拟)
- Ping pong(树状数组)
- 夺冠概率模拟
- hdu(3940)The Angry Birds
- HDU 4462 Scaring the Birds(dfs)
- 蒙特卡罗模拟(使用随机数和概率来解决问题)
- HDU 2995 Another Panda's Birthday Present(条件概率|概率生成函数 )
- SpringMVC之RequestContextHolder分析
- sqlite数据库
- 使用了框架iframe的页面如何跳出框架
- Elasticsearch文档的CRUD
- 深入理解MessageQueue
- Pong’s Birds(概率 模拟)
- 正则表达式 regular expression(四)
- c语言:返回指定字符在指定字符串中第n次出现的位置(从0开始计算)
- java学习记录--ThreadLocal使用案例
- halcon下载与安装(二)
- TFS下载文件已损坏问题
- sublime搭建xdebug
- 银发〔2016〕302号文件,划重点
- Django学习7—数据库使用2—使用api增删改查