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 ...
随机推荐
- LeetCode:21. Merge Two Sorted Lists(Easy)
1. 原题链接 https://leetcode.com/problems/merge-two-sorted-lists/description/ 2. 题目要求 给出两个已经从小到大排序的链表ls1 ...
- Windows2008新建域时Administrator 帐户密码不符合要求
Windows 2008 系统安装完毕后,(环境:在安装的时间,系统没有设置密码.做好系统后,进入制面板添加了密码或按ctrl + alt + del 设置密码后 在服务器管理-角色 ...
- 分分钟搞定redis
随着科技不断的发展,使用到的技术也是更新换代,大家都知道当一个程序用户量上来之后,必然是要做数据缓存的,那么如何去实现的呢,在之前我们一直使用memcache去做数据缓存,现在众所周知主流的缓存技术已 ...
- SQL 注入教程
SQL 注入测评教程 1 准备 安装包:Burpsuit.Python27.sqlmap 2 安装配置 2.1 Burpsuit 1) 解压Burpsuit 2) ...
- 今日Linux下安装部署禅道
我的linux系统是在虚拟机上安装的Ubuntu,禅道在官网www.zentao.net下载安装的开源版的linux64位,采用一键安装包安装.安装前要求:系统上不能有自己安装的mysql .下载的安 ...
- 【app.json】配置说明,不断更新中
app.json文件用来对微信小程序进行全局配置,决定页面文件的路径.窗口表现.设置网络超时时间.设置多 tab 等. 注意: 1) json配置中键名.键值必须使用双引号,不能使用单引号. 2) 以 ...
- Python网络编程(进程通信、信号、线程锁、多线程)
什么是进程通讯的信号? 用过Windows的我们都知道,当我们无法正常结束一个程序时, 可以用任务管理器强制结束这个进程,但这其实是怎么实现的呢? 同样的功能在Linux上是通过生成信号和捕获信号来实 ...
- 03-Mysql数据库----安装与管理
本节掌握内容: mysql的安装.启动 mysql破解密码 统一字符编码 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的 ...
- Fluentd插件使用方法
这里主要介绍从MongoDB同步数据到ODPS.ruby环境的搭建以及fluent_plugin_mongo_odps插件的安装.1.准备工作1.1安装环境要求Ruby 2.1以上Gem 2.4.5以 ...
- pandas DataFrame的修改方法
pandas DataFrame的增删查改总结系列文章: pandas DaFrame的创建方法 pandas DataFrame的查询方法 pandas DataFrame行或列的删除方法 pand ...