博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UESTC 890 Card Trick(DP 纸牌魔术)
阅读量:6210 次
发布时间:2019-06-21

本文共 4221 字,大约阅读时间需要 14 分钟。

题意  给你一些牌  所有正面朝下放桌子上   你选一个起点    翻开那张牌   牌上的数字是几就向前走几步   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
#include
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)
Submit   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-10JQK, and A).

title

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 (1n100) and m (1m10) 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 (2x10) or as a single character (JQK, or A 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 107.

Sample input and output

Sample Input Sample Output
5 22 3 5 3 Q1 1A1 2A1 10A6 12 2 2 2 2 27 12 2 2 2 2 2 23 1010 J K
0.48713777570233253480715730.10000000000000000000000000.10000000000000000000000000.17489233570253142396974900.58307132103217674451174680.62792296111157495562803500.3346565827603272001891974



转载地址:http://ncdja.baihongyu.com/

你可能感兴趣的文章
Kali-linux Arpspoof工具
查看>>
PDF文档页面如何重新排版?
查看>>
基于http协议使用protobuf进行前后端交互
查看>>
bash腳本編程之三 条件判断及算数运算
查看>>
php cookie
查看>>
linux下redis安装
查看>>
弃 Java 而使用 Kotlin 的你后悔了吗?| kotlin将会是最好的开发语言
查看>>
JavaScript 数据类型
查看>>
量子通信和大数据最有市场突破前景
查看>>
StringBuilder用法小结
查看>>
对‘初学者应该选择哪种编程语言’的回答——计算机达人成长之路(38)
查看>>
如何申请开通微信多客服功能
查看>>
Sr_C++_Engineer_(LBS_Engine@Global Map Dept.)
查看>>
非监督学习算法:异常检测
查看>>
《OSPF和IS-IS详解》一2.7 BGP-IGP的路由交换
查看>>
App开发中甲乙方冲突会闹出啥后果?H5 APP 开发可以改变现状吗
查看>>
DS4000更换硬盘
查看>>
C#中[] 、List、Array、ArrayList等数据结构的差异简述
查看>>
memcached线程模型
查看>>
7月份英语测试题
查看>>