Acdream 1113 The Arrow(概率dp)

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

1
1

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 100005

double 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;
}
时间: 2024-08-08 13:54:04

Acdream 1113 The Arrow(概率dp)的相关文章

ACdream 1113 The Arrow (概率dp求期望)

E - The Arrow Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Status Description The history shows that We need heroes in every dynasty. For example, Liangshan Heroes. People hope that these heroes can punish the bad

Acdream 1113 The Arrow(概率dp)

题目链接:传送门 题意: 初始状态在0,每次丢骰子[1,6],如果现在在x,丢的骰子数为y,如果x+y>n那么就还停留在x. 求从0到n所丢骰子次数的期望. 分析: 这题和之前的就更改了一点就是如果现在在x,丢的骰子数为y,如果x+y>n那么就还停留在x. 那么我们设dp[i]表示从i到n要丢的骰子次数的期望 那么 我们设每次有x次的可能留在原地 dp[i] =dp[i]*y/6+dp[i+1]/6+dp[i+2]/6..+1; 然后化简一下得到dp[i]的公式. 代码如下: #include

Codeforces 28C [概率DP]

/* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队伍的期望. 思路: 概率dp dp[i][j][k]代表前i个浴室有j个人最长队伍是k的概率. 枚举第i个浴室的人数.然后转移的时候其实是一个二项分布. */ #include<bits/stdc++.h> using namespace std; int jilu[55]; double dp[

hdu 3076 ssworld VS DDD (概率dp)

///题意: /// A,B掷骰子,对于每一次点数大者胜,平为和,A先胜了m次A赢,B先胜了n次B赢. ///p1表示a赢,p2表示b赢,p=1-p1-p2表示平局 ///a赢得概率 比一次p1 两次p0*p1 三次 p0^2*p1,即A赢的概率为p1+p*p1+p^2*p1+...p^n*p1,n->无穷 ///即a_win=p1/(1-p);b_win=p2/(1-p); ///dp[i][j]表示a赢了j次,b赢了i次的概率 ///dp[i][j]=dp[i-1][j]*b_win+dp[

hdu 3853 概率DP 简单

http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意:有R*C个格子,一个家伙要从(0,0)走到(R-1,C-1) 每次只有三次方向,分别是不动,向下,向右,告诉你这三个方向的概率,以及每走一步需要耗费两个能量,问你走到终点所需要耗费能量的数学期望: 回头再推次,思想跟以前的做过的类似 注意点:分母为0的处理 #include <cstdio> #include <cstring> #include <algorithm>

hdu4089(公式推导)概率dp

题意:有n人都是仙剑5的fans,现在要在官网上激活游戏,n个人排成一个队列(其中主角Tomato最初排名为m), 对于队列中的第一个人,在激活的时候有以下五种情况: 1.激活失败:留在队列中继续等待下一次激活(概率p1) 2.失去连接:激活失败,并且出队列然后排到队列的尾部(概率p2) 3.激活成功:出队列(概率p3) 4.服务器瘫:服务器停止服务了,所有人都无法激活了(概率p4) 求服务器瘫痪并且此时Tomato的排名<=k的概率. 解法:ans[i][j]表示i个人出于第j个位置要到目的状

poj3071(概率DP)

题意:淘汰赛制,2^n(n<=7)个队员.给出相互PK的输赢概率矩阵.问谁最有可能赢到最后. 解法:ans[i][j]表示第i个队员第j轮胜出的概率.赢到最后需要进行n场比赛.算出每个人赢到最后的ans[i][n].写出序号的二进制发现一个规律,两个队员i.j如果碰到,那么一定是在第get(i,j)场比赛碰到的.get(i,j)计算的是i和j二进制不同的最高位,这个规律也比较明显. 代码: /****************************************************

【Foreign】开锁 [概率DP]

开锁 Time Limit: 10 Sec  Memory Limit: 256 MB Description Input Output Sample Input 4 5 1 2 5 4 3 1 5 2 2 5 4 3 1 5 3 2 5 4 3 1 5 4 2 5 4 3 1 Sample Output 0.000000000 0.600000000 0.900000000 1.000000000 HINT Main idea 一个宝箱内有一个可以开启别的宝箱的钥匙,可以选择k个宝箱,询问能开

POJ 2151 Check the difficulty of problems (概率DP)

题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 k 个题的概率,sum[i][j] 表示第 i 个队伍,做出 1-j 个题的概率,ans1等于, T个队伍,至少解出一个题的概率,ans2 表示T个队伍,至少解出一个题,但不超过N-1个题的概率,最后用ans1-ans2即可. 代码如下: #pragma comment(linker, "/STA