2017南宁现场赛E The Champion
Bob is attending a chess competition. Now the competition is in the knockout phase. There are 2^r2r players now, and they will play over rr rounds.
In each knockout round, the remaining players would be divided into pairs, and the winner of each pair would advance to the next knockout round. Finally only one player would remain and be declared the champion.
Bob has already assigned all players in an order while he assigned himself to the k-th site. A better player is located at a site with a smaller number indicating a higher order. The probability that a player with higher order wins a player with lower order is p (0 \le p \le 1)p(0≤p≤1).
Bob notices that arrangement of matches is crucial for the final result.
For example, if there are 44 players and Bob is the second best player (he is the second site), and p = 0.9p=0.9. In the first round, if Bob meets the best player, he will have only 0.1 \times 0.9 = 0.090.1×0.9=0.09 probability to become the champion. However if he does not meet the best player in the first round, he will have 0.9 \times (0.9 \times 0.1 + 0.1 \times 0.9) = 0.1620.9×(0.9×0.1+0.1×0.9)=0.162 probability to become the champion. Now Bob wants to know, what is the winning probability for him in the best arrangement of matches.
Input
The first line in the input contains an integer t (1 \le t \le 63000)t(1≤t≤63000) which is the number of test cases.
For each case, there is only one line containing two integers rr and kk (1 \le r < 64,1 \le k \le 2^r)(1≤r<64,1≤k≤2r) and a float-point number p (0 \le p \le 1)p(0≤p≤1) as described above.
Output
For each case, calculate the winning probability for Bob in the best arrangement. Output the probability with the precision of 66 digits.
样例输入
2
1 1 0.8
2 2 0.9
样例输出
0.800000
0.162000 题意:2^r个人打比赛,一共比r伦决出冠军,主角的实力排在第k位,并且对于所有人,打败比他弱的人概率是p,打败比他强的人概率是(1-p);主角要尽可能的提高获胜的概率,求这个概率即可
思路:如果当前这一轮还有比主角弱的人,主角选择和弱的人对决,若只剩比主角强的人,就只能和强的人比赛。dfs记得记忆化搜索。。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstring>
#include<map>
using namespace std;
#define INF 0x3f3f3f3f
#define EPS 1e-7
typedef unsigned long long ll;
const int N_MAX = +;
const int MOD = 1e10+;
int r;
ll k, qiang, ruo, num;
map<pair<ll, ll>, double>mp;//记忆化搜素
double p; double dfs(ll qiang,ll ruo) {
if (qiang == && ruo == )return ;
if (mp[make_pair(qiang, ruo)] != )return mp[make_pair(qiang, ruo)];
ll nxt_qiang = qiang >> , nxt_ruo = ruo >> ;
if (ruo & ) {//弱的为奇数个,说明强的为偶数个,只要主角和一个弱的打就行了
return mp[make_pair(qiang, ruo)] =p*dfs(nxt_qiang, nxt_ruo);
}
else {//否则弱的是偶数个,强的奇数个
if (ruo != ) {//弱的个数不为0,此时主角还是选择和弱的打,但是总会有一个强的会多出来和弱的打,所以这两者谁赢谁输就要分两种情况
return mp[make_pair(qiang, ruo)] = p*(p*dfs(nxt_qiang + , nxt_ruo - ) + ( - p)*dfs(nxt_qiang, nxt_ruo));
}
else {//没有弱的选手了,主角只能和强的打
return mp[make_pair(qiang, )] = ( - p)*dfs(nxt_qiang, );
}
}
} int main() {
int t; scanf("%d",&t);
while (t--) {
scanf("%d%lld%lf",&r,&k,&p);
mp.clear();
num = 1LL << r;
qiang = k - , ruo = num - k;
double res=dfs(qiang, ruo);
printf("%.6f\n",res);
}
return ;
}
2017南宁现场赛E The Champion的更多相关文章
- 2017acm南宁现场赛 J题 Rearrangement
题意: 给定一个2 * n的矩阵, 和 2 * n 个数, 问能不能通过重排列, 使得任意相邻两数不能被3整除 分析: 这题一直卡到最后, 赛后经对面大佬提醒后, 发现统计所有数模三的结果(0,1,2 ...
- 2017 青岛现场赛 Suffix
Consider n given non-empty strings denoted by s1 , s2 , · · · , sn . Now for each of them, you need ...
- 2017 青岛现场赛 I The Squared Mosquito Coil
Lusrica designs a mosquito coil in a board with n × n grids. The mosquito coil is a series of consec ...
- 2017南宁网络赛 Problem J Minimum Distance in a Star Graph ( 模拟 )
题意 : 乱七八糟说了一大堆,实际上就是问你从一个序列到另个序列最少经过多少步的变化,每一次变化只能取序列的任意一个元素去和首元素互换 分析 : 由于只能和第一个元素去互换这种操作,所以没啥最优的特别 ...
- ACM-ICPC 2017 西安赛区现场赛 K. LOVER II && LibreOJ#6062. 「2017 山东一轮集训 Day2」Pair(线段树)
题目链接:西安:https://nanti.jisuanke.com/t/20759 (计蒜客的数据应该有误,题目和 LOJ 的大同小异,题解以 LOJ 为准) LOJ:https://l ...
- 2017 ICPC区域赛(西安站)--- J题 LOL(DP)
题目链接 problem description 5 friends play LOL together . Every one should BAN one character and PICK o ...
- 2013ACM/ICPC亚洲区南京站现场赛---Poor Warehouse Keeper(贪心)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4803 Problem Description Jenny is a warehouse keeper. ...
- HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛
题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...
- 2013杭州现场赛B题-Rabbit Kingdom
杭州现场赛的题.BFS+DFS #include <iostream> #include<cstdio> #include<cstring> #define inf ...
随机推荐
- PIC32MZ 通过USB在线升级 -- USB CDC bootloader
了解bootloader 的实现,请加QQ: 1273623966 (验证填 bootloader):欢迎咨询或定制bootloader:我的博客主页www.cnblogs.com/geekygeek ...
- Java输出日历写法
package TestString_2; import java.text.ParseException;import java.util.Calendar;import java.util.Gre ...
- JMeter接口响应数据出现乱码的三种解决方法
第一种方法: Content encoding设置为utf-8,若仍为乱码,请用方法2 图1 第二种方法: 修改bin文件夹下的jmeter.properties文件 搜索ISO,把“#sampler ...
- 【java并发编程实战】第七章:取消与关闭
停止线程的几种方式 一般的逻辑停止 public class ThreadInterruptTest { public static volatile boolean cancel = true; p ...
- 深度学习-CNN tensorflow 可视化
tf.summary模块的简介 在TensorFlow中,最常用的可视化方法有三种途径,分别为TensorFlow与OpenCv的混合编程.利用Matpltlib进行可视化.利用TensorFlow自 ...
- Go基础篇【第2篇】: 内置库模块 fmt
fmt官方文档说明:https://studygolang.com/pkgdoc import "fmt" mt包实现了类似C语言printf和scanf的格式化I/O.格式化动作 ...
- HDU 1693 Eat the Trees(插头DP,入门题)
Problem Description Most of us know that in the game called DotA(Defense of the Ancient), Pudge is a ...
- 学习bash——环境配置
一.环境配置文件的重要性 Bash在启动时直接读取这些配置文件,以规划好bash的操作环境. 即使注销bash,我们的设置仍然保存. 二.login shell 通过完整的登录流程取得的bash,称为 ...
- 并查集——poj2236(带权并查集)
题目:Wireless Network 题意:给定n台已损坏计算机的位置和计算机最远通信距离d,然后分别根据命令执行以下两种操作: "O p" (1 <= p <= N ...
- flex builder 4
下载地址(需要登录):http://trials.adobe.com/AdobeProducts/FLBR/4/win32/FlashBuilder_4_LS10.exe 很全的在线帮助文档:http ...