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

  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<cstring>
  4.  
  5. using namespace std;
  6.  
  7. int f[]; // 记录飞行路线
  8. double dp[]; // dp[i]表示在i位置时,距离游戏结束还要投掷次数的期望
  9.  
  10. int main() {
  11. int n,m;
  12. while (~scanf("%d%d",&n,&m) && n+m) {
  13. for (int i=; i<=n+; ++i) f[i] = -,dp[i] = 0.0;
  14. for (int a,b,i=; i<=m; ++i) {
  15. scanf("%d%d",&a,&b);f[a] = b;
  16. }
  17. dp[n] = 0.0; // 在n点的期望步数是0
  18. for (int i=n-; i>=; --i) {
  19. if (f[i] == -) {
  20. for (int j=; j<=; ++j)
  21. dp[i] += (dp[i+j]+) / 6.0;
  22. }
  23. else dp[i] = dp[f[i]];
  24. }
  25. printf("%.4lf\n",dp[]);
  26. }
  27. return ;
  28. }

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. maven下nutz与servlet报错org.nutz.mvc.NutFilter cannot be cast to javax.servlet.Filter

    使用maven搭建nutz时,加入servlet报错:org.nutz.mvc.NutFilter cannot be cast to javax.servlet.Filter 十二月 03, 201 ...

  2. Tomcat配置文件server.xml分析

    本文力求,分析清楚 tomcat 的 server.xml 文件,逐步完善更新 常用来,配置tomcat启动,端口号:配置编码等. apache-tomcat-9.0.10/conf/server.x ...

  3. Element-ui安装与使用(网站快速成型工具)

    我之所以将Element归类为Vue.js,其主要原因是Element是(饿了么团队)基于MVVM框架Vue开源出来的一套前端ui组件.我最爱的就是它的布局容器!!! 下面进入正题: 1.Elemen ...

  4. ring0 SSDTHook

    SSDT 的全称是 System Services Descriptor Table,系统服务描述符表.这个表就是一个把 Ring3 的 Win32 API 和 Ring0 的内核 API 联系起来. ...

  5. 创建React工程:React工程模板

    这是本人初学React做的学习笔记;讲的不是很深,只算是简单的进行介绍. 这是一个小系列.都是在同一个模板中搭建的,但是代码是不能正常执行的. >>index.js <!DOCTYP ...

  6. 好的学习网站和app推荐

    1  W3cschool: http://www.w3school.com.cn/ 菜鸟教程: http://www.runoob.com/ 2 视频学习网站和app:网易云课堂.腾讯课堂.慕课网(h ...

  7. Android 中间白色渐变到看不见的线的Drawable

    用gradient <gradient android:startColor="#00ffffff" android:centerColor="#ffffff&qu ...

  8. Axure 8 Tab制作

    1 在[页面]面板中选中[page1] 2 在[元件库]中选中[动态面板],并拖拽到[设计区域]中 3 双[设计区域]中的动态面板,打开[动态面板管理]页面 4 在[动态面板管理]页面中输入动态面板的 ...

  9. 在Nutz中如何配置多个数据库源,并且带事务控制

    在Nutz中如何配置多个数据库源,并且带事务控制  发布于 560天前  作者 Longitude 995 次浏览  复制  上一个帖子  下一个帖子  标签: 无 在Nutz中如何配置多个数据库源, ...

  10. 在使用HTMLTestRunner时,报告为空,错误提示<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf_8'>

    <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf_8'> Time Elapsed: 0:00:21.3163 ...