标签:style http color os io java ar for 2014
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 J
), Queen (Q
),
and King (K
) count as A
) counts as
Alice stops this procedure as soon as there is no card at position
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 2
-10
, J
, Q
, K
,
and A
).
Illustration of first sample input: my starting position is Q
).
The final Q
card is followed by Q
counts as
For each test case:
J
, Q
, K
,
or A
as specified above).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
Sample Input | Sample Output |
---|---|
5 2 2 3 5 3 Q 1 1 A 1 2 A 1 10 A 6 1 2 2 2 2 2 2 7 1 2 2 2 2 2 2 2 3 10 10 J K |
0.4871377757023325348071573 0.1000000000000000000000000 0.1000000000000000000000000 0.1748923357025314239697490 0.5830713210321767445117468 0.6279229611115749556280350 0.3346565827603272001891974 |
UESTC Online Judge
Copyright (C) 2014 Ruins He(@lyhypacm), Jianjin Fan(@pfctgeorge) and Yun Li(@mzry1992). Project home
Any Problem, Please Report On Issues Page Or Discuss With Us In Mailing List.
Currently online registered users: 6
代码为:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<vector> #include<cmath> #include<string> #include<queue> #define eps 1e-9 #define ll long long #define INF 0x3f3f3f3f using namespace std; const int maxn=2000; double p[maxn],ans; int n,m; int main() { char str[maxn]; int temp; while(~scanf("%d%d",&n,&m)) { memset(p,0,sizeof(p)); int start=m; for(int i=1;i<=n;i++) { scanf("%s",str); p[start]=1; if(str[0]<'A'&&str[0]>='2'&&str[0]<='9') temp=str[0]-'0'; else if(str[0]=='1'||str[0]=='J'||str[0]=='Q'||str[0]=='K') temp=10; else temp=11; start+=temp; } ans=0; for(int i=start;i>=1;i--) { if(p[i]==0) { for(int j=2;j<=11;j++) { temp=(j==10?4:1); p[i]+=temp*p[i+j]; } p[i]=p[i]/13; } if(i<=10) ans+=p[i]; } printf("%.10f\n",ans/10); } return 0; }
标签:style http color os io java ar for 2014
原文地址:http://blog.csdn.net/u014303647/article/details/38945861