Acdream 1113 The Arrow(概率dp)

来源:互联网 发布:淘宝代理销售 编辑:程序博客网 时间:2024/06/18 17:38

The Arrow

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
Submit Statistic Next Problem

Problem Description

The history shows that We need heroes in every dynasty. For example, Liangshan Heroes. People hope that these heroes can punish the bad  guys and recover the justice. Nowadays, we also need heroes to provent us from being chopped, or being attacked by a bomb. 

Kuangbin is a very very very very very.... (very * 1e9 ) good boy, after he knows The Arrow, he want to be The Arrow of China. But he is also a little afraid of being killed by the bad guys. So he decides to throw dices to make the decision.

The dice is a cube with 1 2 3 4 5 6 on it's sides. When he throws a dice, every number is of the same probablity to appear. He will write down a number N in the paper at first, and then throw the dice. When the sum of the number he throwed is less than N, he will keep throwing. But if the sum exceeds N, this throwing does not count.

For example, If the sum is 5,and N is 6, if we throw 2, 5 + 2 > 6, then  the sum keeps to be 5.

If he can end the throwing in a certain time, he will make the decision to become The Arrow.

Now , kuangbin wonders that what's the expectation of the time of throwing dices.

Input

First line, The number of cases t <= 100

In the next t lines, there will be t numbers.

every number is not bigger than 100000

Output

Each test output a number rounded to the second digit.

Sample Input

11

Sample Output

6.00

Source

wuyiqi

Manager

wuyiqi

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<vector>#include<set>#include<map>#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define eps 1e-8#define fre(i,a,b)  for(i = a; i <b; i++)#define free(i,b,a) for(i = b; i >= a;i--)#define mem(t, v)   memset ((t) , v, sizeof(t))#define ssf(n)      scanf("%s", n)#define sf(n)       scanf("%d", &n)#define sff(a,b)    scanf("%d %d", &a, &b)#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)#define pf          printf#define bug         pf("Hi\n")using namespace std;#define INF 0x3f3f3f3f#define N 100005double dp[N];int main(){    int i,j,t,n;    sf(t);    while(t--)    {        sf(n);        mem(dp,0);        for(i=n-1;i>=0;i--)        {           double te=0;           int k=0;           for(j=1;j<=6;j++)             if(i+j>n) k++;     //回到原地             else te+=1.0/6*dp[i+j];   //不回原地           dp[i]=(te+1)/(6-k)*6;           }        pf("%.2lf\n",dp[0]);    }  return 0;}









0 0
原创粉丝点击