UESTC 890 Card Trick(DP 纸牌魔术)
题意 给你一些牌 所有正面朝下放桌子上 你选一个起点 翻开那张牌 牌上的数字是几就向前走几步 J,Q,K 都是向前走10步 A向前走11步 知道向前走相应的步数后超过了终点 输入n m 和n个数 代表你以第m张牌为起点 依次掀开了n张牌就不能再掀了 然后相同的牌 Alice以1-10张牌中的随意一个为起点 求Alice最后的终点与你的终点相同的概率
c[i]表示第i张牌的面值 没被掀开的牌的面值都是未知的c[i]=0 可能为2-A中的随意一个 令d[i]表示从你的终点到达第i张牌的概率 那么全部掀开过的牌的概率都为1 然后从终点向前递推 当p[i]=0时 p[i]=sum{p[i+j]} j为2-A中随意一张牌 注意10,j,q,k的时候都是10 最后的答案就是1到10的结果加起来除以10了
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1500; int main()
{
char s[3];
int n, m, l;
double p[N], ans;
while (~scanf ("%d%d", &n, &m))
{
memset (p, 0, sizeof (p));
l = m; for (int i = 1; i <= n; ++i)
{
scanf ("%s", s);
p[l] = 1;
if (s[0]<'A' && s[1]!='0') l += s[0] - '0';
else if (s[0] == 'A') l += 11;
else l+= 10;
} ans = 0;
for (int i = l ; i >= 1; --i)
{
if (p[i] == 0)
{
for (int j = 2; j <= 11; ++j)
{
int t = (j == 10 ? 4 : 1);
p[i] += t * p[i + j];
}
p[i] /= 13;
}
if (i <= 10) ans += p[i];
} printf ("%.8f\n", ans / 10);
}
return 0;
}
Card Trick
Time Limit: 2999/999MS (Java/Others) Memory Limit: 65432/65432KB (Java/Others)
Status
I am learning magic tricks to impress my girlfriend Alice. My latest trick is a probabilistic one, i.e. it does work in most cases, but not in every case. To perform the trick, I first shuffle a set of many playing cards and put
them all in one line with faces up on the table. Then Alice secretly selects one of the first ten cards (i.e. she chooses x0,
a secret number between 1 and 10 inclusive)
and skips cards repeatedly as follows: after having selected a card at position xi with
a number c(xi) on
its face, she will select the card at position xi+1=xi+c(xi).
Jack (J
), Queen (Q
),
and King (K
) count as 10,
Ace (A
) counts as 11.
You may assume that there are at least ten cards on the table.
Alice stops this procedure as soon as there is no card at position xi+c(xi).
I then perform the same procedure from a randomly selected starting position that may be different from the position selected by Alice. It turns out that often, I end up at the same position. Alice is very impressed by this trick.
However, I am more interested in the underlying math. Given my randomly selected starting position and the card faces of every selected card (including my final one), can you compute the probability that Alice chose a starting
position ending up on the same final card?
You may assume that her starting position is randomly chosen with uniform probability (between 1 and 10 inclusive).
I forgot to note the cards that I skipped, so these cards are unknown. You may assume that the card face of every single of the unknown cards is independent of the other card faces and random with uniform probability out of the possible card faces (i.e. 2
-10
, J
, Q
, K
,
and A
).
Illustration of first sample input: my starting position is 2,
so I start selecting that card. Then I keep skipping cards depending on the card's face. This process iterates until there are not enough cards to skip (in this sample: Q
).
The final Q
card is followed by 0 to 9 unknown
cards, since Q
counts as 10.
Input
For each test case:
- A line containing two integers n (1≤n≤100) and m (1≤m≤10)
where n is
the number of selected cards and m is
the 1-based
position of my first selected card. - A line with n tokens
that specify the n selected
card faces (in order, including the final card). Each card face is given either as an integer x (2≤x≤10)
or as a single character (J
,Q
,K
,
orA
as specified above).
Output
For each test case, print one line containing the probability that Alice chooses a starting position that leads to the same final card. Your output should have an absolute error of at most 10−7.
Sample input and output
Sample Input | Sample Output |
---|---|
5 2 |
0.4871377757023325348071573 |
UESTC 890 Card Trick(DP 纸牌魔术)的更多相关文章
- ny714 Card Trick
Card Trick 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 The magician shuffles a small pack of cards, holds ...
- HDU 2319 Card Trick (模拟)
题目链接 Problem Description The magician shuffles a small pack of cards, holds it face down and perform ...
- UESTC 876 爱管闲事 --DP
题意:即求给定n个数字(a1,a2,……an),不改变序列,分成M份,使每一份和的乘积最大. 思路:dp[i][j]表示把前i个数字,分成j份所能得到的最大乘积. 转移方程:dp[i][j] = ma ...
- UESTC 923 稳住GCD DP + GCD
定义:dp[i][j] 表示 在前i个数中,使整个gcd值为j时最少取的数个数. 则有方程: gg = gcd(a[i],j) gg == j : 添加这个数gcd不变,不添加, dp[i][j] ...
- 【CSA49F】【XSY3317】card 博弈论 DP
题目大意 不会博弈论的 yww 在和博弈论大师 yxq 玩一个游戏. 有 \(n\) 种卡牌,第 \(i\) 种卡牌有 \(b_i\) 张. yww 会先把所有 \(B=\sum_{i=1}^nb_i ...
- CF760 D Travel Card 简单DP
link 题意:乘车,有3种票 1.20块坐1站 2.坐90分钟,50块 3.坐1440分钟,120块 现给出到达每个站的时间,问最优策略 思路: 简单DP,限定条件的3个转移方向,取最小的那个就行了 ...
- Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
- SPOJ 1108 Card Trick 暴力模拟
解释一下样例,因为我觉得这个题意表述的不是很清楚.以第二组样例为例. 牌序为:3 1 4 5 2 第一轮:把 3 放到末尾:1 4 5 2 3,最顶上的牌是1,把1拿走.剩余 4 5 2 3 第二轮: ...
- POJ 2200 A Card Trick(模拟)
题目链接 题意 : 一共52张牌(A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K)花色分别是C,D,H,S ...给助理5张牌,然后助理需要重新排一下次序,把第一张牌给观 ...
随机推荐
- 状态管理cookie 案例
1状态管理:服务器为了追踪同一个客户端发出的请求,将多次交互看成一个整体看待 2:cookie的生存时间,默认情况下,cookie保存在浏览器内存中,只要不关闭浏览器,cookie就一直存在 如果希望 ...
- SQL Server 2008 备份改进版
1.Add compressing function with 7-Zip 2.With tool win.rar code so you can change it if you want USE ...
- 【kd-tree】专题总结
感谢orz神·小黑的指导 kd-tree就是用来计算若干维空间k近/远点的数(shou)据(suo)结(you)构(hua) 建树 假设题目是k维的点 第deep层就是用deep%k+1维把所有点分为 ...
- Kali Linux 安装教程-转
rootoorotor昨天折腾了 Kali Linux 1.0,把大概的配置过程记录下来,希望对想接触或使用Kali Linux的同学有所帮助. 请注意: 1.本文为面向新手的教程,没技术含量,没 ...
- WebRTC源码分析:音频模块结构分析
一.概要介绍WebRTC的音频处理流程,见下图: webRTC将音频会话抽象为一个通道Channel,譬如A与B进行音频通话,则A需要建立一个Channel与B进行音频数据传输.上图中有三个Chann ...
- 对比AMD 890、AMD 880、 AMD 790、AMD 785、 AMD 780、AMD 7
770无集显.中低端独显主流. 780G带集显.现在可以无视. 785G现在是带集显的主流. 790GX高端带集显. 790FX专高端,无集显. 790X带集显.基本无视. 870 大板,无集显 88 ...
- Live m3u8播放3个文件自动停止问题
Live m3u8播放3个文件自动停止问题 1.问题描述 最近做一个转码切片播放测试,使用HLS(HTTP Live Streaming)来做直播, 每个TS分片时间为10s,根据TS分片文件生成以下 ...
- Perl初识笔记
前两天项目中遇到了一个Perl脚本程序,需要读懂该程序,由于以前重来没有用过Perl语言,所以没法搞定.今天抽空把该语言的基础看了一遍,基本上内读懂Perl脚本程序了吧.真是如网上很多分享的经验所说, ...
- IllegalStateException
例1 public static void main(String[]sdf){ List<String> list = new ArrayList<String>(); li ...
- Android PHP 通过JSON进行数据交互
一.首先是Android客户端解析PHP返回的JSON数据 1.PHP代码(这里用到了数据库,如果没有准备数据库的话,可以自定义字符串) <?php $link=mysql_connect(SA ...