Aeroplane chess

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1581    Accepted Submission(s): 1082

Problem Description
Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the numbers on the faces are 1,2,3,4,5,6). When Hzz is at grid i and the dice number is x, he will moves to grid i+x. Hzz finishes the game when i+x is equal to or greater than N.
There are also M flight lines on the chess map. The i-th flight line can help Hzz fly from grid Xi to Yi (0<Xi<Yi<=N) without throwing the dice. If there is another flight line from Yi, Hzz can take the flight line continuously. It is granted that there is no two or more flight lines start from the same grid.
Please help Hzz calculate the expected dice throwing times to finish the game.
 
Input
There are multiple test cases. Each test case contains several lines. The first line contains two integers N(1≤N≤100000) and M(0≤M≤1000). Then M lines follow, each line contains two integers Xi,Yi(1≤Xi<Yi≤N).   The input end with N=0, M=0.
 
Output
For each test case in the input, you should output a line indicating the expected dice throwing times. Output should be rounded to 4 digits after decimal point.
 
Sample Input
2 0
8 3
2 4
4 5
7 8
0 0
 
Sample Output
1.1667
2.3441
 
Source
 
有一个长条形棋盘,每一次可以跳1,2,3,4,5,6中的一种的距离,且每一跳的概率相等1/6;且在某一个点出有一个航班可以帮助他不需要跳直接可以达到y处
问到n平均需要跳多少次。
 
    dp【n】=0;因为在哪里不需要再跳,这个已知,所以可以倒退
    dp[i]=sum{1+dp[n+j]}(1<=j<=6)
 代码:

 #include<cstdio>
#include<cstring>
#include<stack>
#define maxn 100008
using namespace std;
double dp[maxn];
stack<int> path[maxn];
int pa[maxn];
int main()
{
int n,m,a,b;
while(scanf("%d%d",&n,&m)!=EOF&&n+m)
{
memset(pa,,sizeof(int)*(n+));
memset(dp,,sizeof(double)*(n+));
while(m--)
{
scanf("%d%d",&a,&b);
path[b].push(a);
pa[a]=b;
}
while(--n>=)
{
while(!path[n+].empty())
{
dp[path[n+].top()]=dp[n+];
path[n+].pop();
}
if(pa[n]==)
dp[n]=1.0+(dp[n+]+dp[n+]+dp[n+]+dp[n+]+dp[n+]+dp[n+])/6.0;
}
printf("%.4lf\n",dp[]);
}
return ;
}

hdu 4405Aeroplane chess(概率DP)的更多相关文章

  1. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

  2. HDU 3853LOOPS(简单概率DP)

    HDU 3853    LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...

  3. HDU - 1099 - Lottery - 概率dp

    http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[ ...

  4. HDU 4405 【概率dp】

    题意: 飞行棋,从0出发要求到n或者大于n的步数的期望.每一步可以投一下筛子,前进相应的步数,筛子是常见的6面筛子. 但是有些地方可以从a飞到大于a的b,并且保证每个a只能对应一个b,而且可以连续飞, ...

  5. HDU 4576 Robot(概率dp)

    题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...

  6. HDU 4599 Dice (概率DP+数学+快速幂)

    题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n ...

  7. [HDU 4089]Activation[概率DP]

    题意: 有n个人排队等着在官网上激活游戏.Tomato排在第m个. 对于队列中的第一个人.有以下情况: 1.激活失败,留在队列中等待下一次激活(概率为p1) 2.失去连接,出队列,然后排在队列的最后( ...

  8. hdu 3853 LOOPS 概率DP

    简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  9. HDU 3853 期望概率DP

    期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每一个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] ,  右移:[x][y ...

随机推荐

  1. Java IO流整理Rick

    Java 流IO部分: Console 控制台信息读取// ----------- Console Begin // ------------ 部分代码  Console cons ;  char[] ...

  2. 【翻译】《深入解析windows操作系统第6版下册》第10章:内存管理

    [翻译]<深入解析windows操作系统第6版下册>第10章:内存管理(第一部分) [翻译]<深入解析windows操作系统第6版下册>第10章:内存管理(第二部分) [翻译] ...

  3. 起点CG原创教程——digicel.FlipBook.6教程

    http://blog.renren.com/blog/262793929/473221163

  4. 验证SMB登入

    使用SMB登入扫描器对大量主机的用户名和口令进行猜解,不过扫描动静很大,容易被察觉,而且每一次登入尝试都会被扫描的主机系统日志记录下来,留下痕迹不建议使用. 实例 第一步: msf > use ...

  5. IDoc

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  6. python_way,day4 内置函数(callable,chr,随机验证码,ord),装饰器

    python_way,day4 1.内置函数 - 下 制作一个随机验证码 2.装饰器 1.内置函数 - 下 callable() #对象能否被调用 chr() #10进制数字对应的ascii码表中的内 ...

  7. LTE Module User Documentation(翻译1)——背景、使用概述、基本的仿真程序和配置LTE模型参数

    LTE用户文档 (如有不当的地方,欢迎指正!) 1.背景 假定读者已经熟悉 ns-3 simulator ,能运行一般的仿真程序.如果不是的话,强烈推荐读者参考 [ns3tutorial].   2. ...

  8. Scrum Meeting---Two(2015-10-26)

    这次会议主要有两个方面 一.讨论项目 经过我们团队的激烈讨论,我们团队决定专注于做二手交易这一块.即将之前决定要做的学习经验交流以及校园交由这两块删除. 二.后两天的任务规划 以下便是我们的任务规划: ...

  9. javascript练习----复选框全选,全不选,反选

    第一种方式: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  10. MyEclipse Servers视窗出现“Could not create the view: An unexpected exception was thrown”错误解决办法

    打开所在的wordspace文件夹,在下面子文件夹 .metadata\.plugins\org.eclipse.core.runtime\.settings\com.genuitec.eclipse ...