Aeroplane chess

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

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

题意

一个1*n的网格,每次都可以以相同的概率从一个点往后跳1~6个点;另有m条路线,a->b表示从a只能直接跳到b。跳到大于等于n,后结束游戏,求结束游戏的步数期望。

分析

dp[i]表示从i点开始,到结束游戏的期望。

那么dp[n]=0,

dp[i]=(dp[j]+1)/6   j=i+1,i+2...i+6;

如果i处有飞行线,那么dp[i]=dp[f[i]]   f[i]是i点到达的点。

code

 #include<cstdio>
#include<algorithm>
#include<cstring> using namespace std; int f[]; // 记录飞行路线
double dp[]; // dp[i]表示在i位置时,距离游戏结束还要投掷次数的期望 int main() {
int n,m;
while (~scanf("%d%d",&n,&m) && n+m) {
for (int i=; i<=n+; ++i) f[i] = -,dp[i] = 0.0;
for (int a,b,i=; i<=m; ++i) {
scanf("%d%d",&a,&b);f[a] = b;
}
dp[n] = 0.0; // 在n点的期望步数是0
for (int i=n-; i>=; --i) {
if (f[i] == -) {
for (int j=; j<=; ++j)
dp[i] += (dp[i+j]+) / 6.0;
}
else dp[i] = dp[f[i]];
}
printf("%.4lf\n",dp[]);
}
return ;
}

HDU 4405 Aeroplane chess(期望dp)的更多相关文章

  1. HDU 4405 Aeroplane chess 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...

  2. [ACM] hdu 4405 Aeroplane chess (概率DP)

    Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...

  3. HDU 4405 Aeroplane chess(概率dp,数学期望)

    题目 http://kicd.blog.163.com/blog/static/126961911200910168335852/ 根据里面的例子,就可以很简单的写出来了,虽然我现在还是不是很理解为什 ...

  4. HDU 4405 Aeroplane chess 概率DP 难度:0

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...

  5. HDU 4405 Aeroplane chess (概率DP)

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

  6. hdu 4405 Aeroplane chess(简单概率dp 求期望)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. hdu 4405 Aeroplane chess (概率DP)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. hdu 4405 Aeroplane chess(概率+dp)

    Problem Description Hzz loves aeroplane chess very much. The chess map contains N+ grids labeled to ...

  9. 【HDU4405】Aeroplane chess [期望DP]

    Aeroplane chess Time Limit: 1 Sec  Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...

  10. 【刷题】HDU 4405 Aeroplane chess

    Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled fr ...

随机推荐

  1. 一次ddos攻击

    公司lvs的vip受到攻击,表现现象为: 1)vip所有服务器没有什么连接,大量的无效connection 2)网卡流量很大 停用vip,流量下降,临时解决攻击问题.但是这只是治标不治本,如果攻击方变 ...

  2. vos限制客户呼出时间

    问题: 公司希望自己的卡线晚上 21:00-24:00    早上00:00-7:30不能打出电话,以防遭投拆, 那么如何设置? 方法: 找到客户使用的落地网关, 落地网关——补充设置——

  3. JavaScript 常用的Math对象

    Math.ceil(x); //返回x向上取整后的整数值. Math.floor(x); //返回x向下取整后的整数值.. Math.round(x); //返回四舍五入后的整数. Math.abs( ...

  4. 酷狗音乐PC端怎么使用听歌识曲功能?

    生活中很多时候会听到一些美妙的音乐,耳熟或者动听却不知道它的名字.就像第一眼看到你心动的那个她却不知她叫什么.移动端有酷狗音乐的听歌识曲.现在PC端也有了相同的功能,每当我们看到一部精彩影视剧听到美妙 ...

  5. Linux 命令后台运行

    写这个随笔主要是每次Deepin用shadowsocks的时候总需要命令行启动,然后一个终端就一直开着总是点错了就给关了. (不知道为什么我的Deepin的shadowsocks-qt5总是连接不上的 ...

  6. 【PHP 模板引擎】Prototype 原型版发布!

    在文章的开头,首先要向一直关注我的人说声抱歉!因为原本是打算在前端框架5.0发布之后,就立马完成 PHP 模板引擎的初版.但我没能做到,而且一直拖到了15年元旦才完成,有很严重的拖延症我很惭愧,再次抱 ...

  7. 2017.9.16 Web 应用开发环境搭建与开发工具安装

    1.JDK的下载与安装 1.1 在网址:http://javase/downloads/index.jsp网站下载最新的JDK版本 1.2 安装jdk,双击下载好的.exe文件运行,一般默认安装在c盘 ...

  8. Laravel5 构造器高级查询条件写法

    <?php #DB 高级查询 // select * from table where A and B or C $all_data = DB::table("shopnc_goods ...

  9. 安装juicer

    由于我第一次安装 JUICER时遇到了很多问题,现在把这些问题都记录下来,给同样第一次安装使用的同学一点借鉴. 前面已经安装了Torch3和Tracter,这都是为安装Juicer做的准备,现在安装J ...

  10. 大数据(1)初始hadoop

    1.hadoop模型如下: (上图为Hadoop1.x的布局) (Hadoop2.x较Hadoop1.x,多了YARN) Hadoop框架,是一个庞大的生态系统. 或者我们可以这样理解: 可以把整个体 ...