HDU4405-Aeroplane chess(概率DP求期望)
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.
InputThere 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.
OutputFor 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
- 本题题意:数轴上有N+1个点(编号0~N),一个人玩游戏,从0出发,当到达N或大于N的点则游戏结束。
每次行动掷骰子一次,骰子编号1-6,掷到多少就向前走几步,这个数轴上还有些特殊点,这些点类似
飞行棋中的飞行点,只要到达这些点就可以直接飞到给定点。求总共投掷骰子次数的期望。- 题解:如果直接可以飞行就f[i]=f[reach],然后就是递推吧。
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<iostream>
- #include<cmath>
- #define ll long long
- #define N 100007
- int n,m;
- double f[N];
- int go_to[N];
- int main()
- {
- while(~scanf("%d%d",&n,&m)&&(n+m))
- {
- memset(go_to,-,sizeof(go_to));
- memset(f,,sizeof(f));
- int x,y;
- for(int i=;i<=m;i++)
- {
- scanf("%d%d",&x,&y);
- go_to[x]=y;
- }
- for(int i=n-;i>=;i--)
- {
- if(go_to[i]==-)
- {
- for(int j=;j<=;j++){
- f[i]+=f[i+j]/6.0;
- }
- f[i]+=;
- }
- else f[i]=f[go_to[i]];
- }
- printf("%.4lf\n",f[]);
- }
- }
HDU4405-Aeroplane chess(概率DP求期望)的更多相关文章
- HDU4405 Aeroplane chess (概率DP,转移)
http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:在一个1×n的格子上掷色子,从0点出发,掷了多少前进几步,同时有些格点直接相连,即若a,b相连,当落 ...
- [hdu4405]Aeroplane chess(概率dp)
题意:某人掷骰子,数轴上前进相应的步数,会有瞬移的情况,求从0到N所需要的期望投掷次数. 解题关键:期望dp的套路解法,一个状态可以转化为6个状态,则该状态的期望,可以由6个状态转化而来.再加上两个状 ...
- HDU3853-LOOPS(概率DP求期望)
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- POJ2096 Collecting Bugs(概率DP,求期望)
Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...
- hdu 4405 Aeroplane chess(简单概率dp 求期望)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- [ACM] hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- LightOJ 1030 【概率DP求期望】
借鉴自:https://www.cnblogs.com/keyboarder-zsq/p/6216762.html 题意:n个格子,每个格子有一个值.从1开始,每次扔6个面的骰子,扔出几点就往前几步, ...
- HDU-4405 Aeroplane chess(概率DP求期望)
题目大意:一个跳棋游戏,每置一次骰子前进相应的步数.但是有的点可以不用置骰子直接前进,求置骰子次数的平均值. 题目分析:状态很容易定义:dp(i)表示在第 i 个点出发需要置骰子的次数平均值.则状态转 ...
随机推荐
- 洛谷 P1438 无聊的数列
题目背景 无聊的YYB总喜欢搞出一些正常人无法搞出的东西.有一天,无聊的YYB想出了一道无聊的题:无聊的数列...(K峰:这题不是傻X题吗) 题目描述 维护一个数列{a[i]},支持两种操作: 1.1 ...
- mac ssd开启trim模式
开启方法 sudo trimforce enable
- aspose.cell 给excel表格设置样式
方法1: Style styleTitle = workbook.Styles[workbook.Styles.Add()];//新增样式 styleTitle.HorizontalAlignment ...
- 集成iAd广告
在iPhone程序中集成广告,管他能不能赚钱,不放上一个iAd就心有不甘. 参考了下面这篇文章: http://bees4honey.com/blog/tutorial/how-to-add-iad- ...
- Mac下搜索神兵利器Alfred 3.1.1最新和谐版
http://bbs.feng.com/read-htm-tid-9891194.html 相比Windows而言Mac自带的Spotlight搜索已经非常强大了,尤其是Mac OS Yosemite ...
- 修改visual studio setup 安装顺序(解决新版安装包无法自动移除老版本程序的问题)
背景 visual studio setup 支持自动删除之前版本的安装,需要设置RemovePreviousVersions = true, DetectNewerInstalledVersion ...
- Linux文件的IO操作 一
系统调用 系统调用: 操作系统提供给用户程序调用的一组“特殊”接口,用户程序可以通过这组“特殊”接口来获得操作系统内核提供的服务 为什么用户程序不能直接访问系统内核提供的服务 为了更好地保护内核空间, ...
- velocity生成静态页面代码
首先需要必备的jar包: web.xml <!-- load velocity property --> <servlet> <servlet-name>veloc ...
- 监控linux各主机系统时间是否一致
#!/bin/bashSTATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3PASSWD='**************'print_h ...
- javascript基础知识 (八) BOM学习笔记
一.什么是BOM BOM(Browser Object Model)即浏览器对象模型. BOM提供了独立于内容 而与浏览器窗口进行交互的对象: 由于BOM主要用于管理窗口 ...