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. Windows下通过bat脚本实现自动上传文件到ftp服务器

    @Echo Off Echo open ip_address [port] >ftp.up Echo [username]>>ftp.up Echo [password]>&g ...

  2. Examples For When-Validate-Item trigger In Oracle Forms

    The following example finds the commission plan in the COMMPLAN table, based on the current value of ...

  3. CHECKBOX_CHECKED built-in in Oracle D2k Forms

    CHECKBOX_CHECKED built-in in Oracle D2k Forms DescriptionA call to the CHECKBOX_CHECKED function ret ...

  4. 巧遇"drwxr-xr-x."权限

    drwxr-xr-x. 是SELinux的问题 REDHAT6之后安全提高所以设置的 关闭SELINUX就好了 因为新版本ls把多acl和selinux属性加进去了,与系统无关,新版本的ls代码使用1 ...

  5. [SAP ABAP开发技术总结]动态修改选择屏幕

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

  6. yii-mail yii 发送邮件

    参考网址:http://shoukii0721.iteye.com/blog/1576225 有很多时候我们需要给用户发送邮件,作留言,或者是激活邮件.等用途. 需要注意的是,设置发送的邮件得有SMT ...

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

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

  8. CDN学习笔记一(CDN是什么?)

    CDN是什么? 谈到CDN的作用,可以用8年买火车票的经历来形象比喻: 8年前,还没有火车票代售点一说,12306.cn更是无从说起.那时候火车票还只能在火车站的售票大厅购买,而我所住的小县城并不通火 ...

  9. 安装64位版Oracle11gR2后无法启动SQLDeveloper的解决方案(原创) (2016-10-29 下午01:56)

    安装64位版Oracle11gR2后发现启动SQL Developer时弹出配置java.exe的路径,找到Oracle自带java.exe后产生的路径"C:\app\用户名\product ...

  10. Python循环嵌套

    可以在循环体内嵌入其他的循环体,如在while循环中可以嵌入for循环, 反之,你可以在for循环中嵌入while循环. 实例: 以下实例使用了嵌套循环输出3~13之间的素数: 以上实例输出结果: F ...