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的更多相关文章

  1. 2017acm南宁现场赛 J题 Rearrangement

    题意: 给定一个2 * n的矩阵, 和 2 * n 个数, 问能不能通过重排列, 使得任意相邻两数不能被3整除 分析: 这题一直卡到最后, 赛后经对面大佬提醒后, 发现统计所有数模三的结果(0,1,2 ...

  2. 2017 青岛现场赛 Suffix

    Consider n given non-empty strings denoted by s1 , s2 , · · · , sn . Now for each of them, you need ...

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

  4. 2017南宁网络赛 Problem J Minimum Distance in a Star Graph ( 模拟 )

    题意 : 乱七八糟说了一大堆,实际上就是问你从一个序列到另个序列最少经过多少步的变化,每一次变化只能取序列的任意一个元素去和首元素互换 分析 : 由于只能和第一个元素去互换这种操作,所以没啥最优的特别 ...

  5. ACM-ICPC 2017 西安赛区现场赛 K. LOVER II && LibreOJ#6062. 「2017 山东一轮集训 Day2」Pair(线段树)

    题目链接:西安:https://nanti.jisuanke.com/t/20759   (计蒜客的数据应该有误,题目和 LOJ 的大同小异,题解以 LOJ 为准)     LOJ:https://l ...

  6. 2017 ICPC区域赛(西安站)--- J题 LOL(DP)

    题目链接 problem description 5 friends play LOL together . Every one should BAN one character and PICK o ...

  7. 2013ACM/ICPC亚洲区南京站现场赛---Poor Warehouse Keeper(贪心)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4803 Problem Description Jenny is a warehouse keeper. ...

  8. HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛

    题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...

  9. 2013杭州现场赛B题-Rabbit Kingdom

    杭州现场赛的题.BFS+DFS #include <iostream> #include<cstdio> #include<cstring> #define inf ...

随机推荐

  1. 【好帖】 Mark

    1. 管理篇 2. 程序员选择公司的8个标准 3. 实用工具 4. 离职跳槽 5. DBA 6. 做一个网站多少钱? 7. 十大算法 8. 寻求用户评价App的正确方法 9. 工程师忽略的隐形成本 1 ...

  2. CentOS 7 安装Nginx并实现域名转发

    CentOS 7 条件 教程中的步骤需要root用户权限. 一.添加Nginx到YUM源 添加CentOS 7 Nginx yum资源库,打开终端,使用以下命令: sudo rpm -Uvh http ...

  3. Qt Demo Http 解析网址 Openssl

    今天练习了一下Qt 解析http协议,在Demo中使用到了Openssl 一上午的时间都是编译openssl,不过还是没有成功,很遗憾,这里整理了有关这个Demo的本件 网盘连接:见下方评论吧,长传太 ...

  4. VMware快照

    越来越多的人喜欢使用虚拟机来做实验,但是实验过程并不总是顺利的,所以我们就需要掌握虚拟机快照的使用方法,个人建议的顺序为: 1 在虚拟机打开之前,点击“虚拟机”--"快照"--&q ...

  5. [P2387魔法森林

    题面 题意: 给出一个图,边权有两维,a与b. 求1到n的一条路径使得路径经过的边的最大的a与b的和最小,输出最小之和. \(Solution:\) 如果做过这题,那么就显得很简单了很好想了. 又是想 ...

  6. Visual Studio 6.0安装包

    点击下载

  7. day-10 sklearn库实现SVM支持向量算法

    学习了SVM分类器的简单原理,并调用sklearn库,对40个线性可分点进行训练,并绘制出图形画界面. 一.问题引入 如下图所示,在x,y坐标轴上,我们绘制3个点A(1,1),B(2,0),C(2,3 ...

  8. linux学习(二)——汤哥的推荐书籍

    成为一名精通 Linux程序设计的高级程序员一直是不少朋友孜孜以求的目标. 根据中华英才网统计数据,北京地区 Linux 程序员月薪平均为 Windows程序员的 1.8 倍.Java 程序员的 2. ...

  9. 项目启动报错: No naming context bound to this class loader

    发步项目到本地tomcat,启动后,一直包错:  警告: Failed to retrieve JNDI naming context for container [StandardEngine[Ca ...

  10. Jquery 跨域请求JSON数据问题

    制作网站时,我们有时候为了方便快捷会调用别人写好的API接口,或者是调用一些免费的API接口获得JSON数据.比如天气,农历,网站备案信息查询等. 但是,这些API接口都是别人自己服务器上的,我们要调 ...