The ArrowTime limit:2000/1000ms (java/others)Memory limit:128000/64000kb (java/others)Submit statistic Next Problemproblem 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 being the arrow of China. But he's 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 was of the same probablity to appear. He would write down a number N in the paper at first, and then throw the dice. When the sum of the number he throwed was less than N, he would keep throwing. But if the sum is exceeds N, this throwing does not count.
For example, if the sum is 5,and N are 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'll make the decision to become the Arrow.
Now, Kuangbin wonders, the expectation of the time of the throwing dices.
Input
First line, the number of cases T <=
In the next T lines, there would be T numbers.
Every number is not bigger than 100000
Outputeach test output A number rounded to the second digit. Sample Input
11
Sample Output
6.00
Sourcewuyiqimanagerwuyiqi
#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") usin G 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++;Back in place else te+=1.0/6*dp[i+j]; Do not return to situ dp[i]= (te+1)/(6-k) *6; } PF ("%.2lf\n", dp[0]); } return 0;}
Acdream 1113 the Arrow (probability DP)