题目:

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

题解:

  期望dpsb题···不多说了

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+;
double f[N];
int n,m,to[N];
inline int R(){
char c;int f=;
for(c=getchar();c<''||c>'';c=getchar());
for(;c<=''&&c>='';c=getchar()) f=(f<<)+(f<<)+c-'';
return f;
}
int main(){
//freopen("a.in","r",stdin);
while(scanf("%d%d",&n,&m)){
if(n==&&m==) break;
memset(to,,sizeof(to));memset(f,,sizeof(f));int a,b;
for(int i=;i<=m;i++) a=R(),b=R(),to[a]=b;
for(int i=n-;i>=;i--){
if(to[i]){
f[i]=f[to[i]];continue;
}
for(int j=;j<=;j++)
f[i]+=(f[i+j]+)/;
}
printf("%0.4f\n",f[]);
}
return ;
}

刷题总结——Aeroplane chess(hdu4405)的更多相关文章

  1. 【刷题】HDU 4405 Aeroplane chess

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

  2. hdu4405 Aeroplane chess

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

  3. HDU-4405 Aeroplane chess

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 看了一下这个博客http://kicd.blog.163.com/blog/static/12696191 ...

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

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

  5. 【HDOJ】【4405】Aeroplane chess飞行棋

    概率DP/数学期望 kuangbin总结中的第4题 啊还是求期望嘛……(话说Aeroplane chess这个翻译怎么有种chinglish的赶脚……) 好像有点感觉了…… 首先不考虑直飞的情况: f ...

  6. HDU 4405 Aeroplane chess 期望dp

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

  7. LeetCode刷题系列

    LeetCode 我们工作面试和提高自身数据结构和算法能力的时候往往需要刷刷题,我选择LeetCode是通过一个留学论坛了解的.专业,覆盖语种全面. 提前说说刷题的心得: 尽量手写代码,少使用IDE的 ...

  8. ife任务刷题总结(一)-css reset与清除浮动

    本文同时发布于本人的个人网站www.yaoxiaowen.com 百度创办的前端技术学院,是一个面向大学生的前端技术学习平台.虽然只有大学生才有资格报名,提交代码进行比赛排名.但是这并不妨碍我们这些初 ...

  9. 刷题ING...

    我用codeVS刷题.. 努力准备!!

随机推荐

  1. Java分享笔记:泛型机制的程序演示

    package packA; import java.util.*; public class GenericDemo { public static void main(String[] args) ...

  2. UVA_10139

    The factorial function, n! is defined thus for n a non-negative integer:0! = 1 n! = n×(n−1)! (n > ...

  3. 将 cmd 中命令输出内容保存为 TXT 文本文件

    如果执行的命令输出内容较多,那么 cmd 控制台将会自动清除前面的内容,那么如何将屏幕的所有内容导出到文本文件? 下面给出简单的演示例子 ping百度,不会自动结束,按 Ctrl+C 强制结束,pin ...

  4. shell 脚本入门

    shell script 是一个程序化脚本,使用shell语法跟linux命令完成的一个程序. 注意事项: 文件开头: #!/bin/bash 文本以enter符号作为开始执行该行语句,用跳脱符 \e ...

  5. 【Codebase】JQuery获取表单部分数据提交方法

    JQuery使用ajax提交整个表单最简便的方法就是$('#form').serialize();但如果仅想保存表单中的部分数据,比如仅更新选中的条目,那么获取数据就比较麻烦了. 解决方法:新建一个表 ...

  6. php扩展开发-常量

    //常量在内核中的结构 typedef struct _zend_constant { zval value; int flags; char *name; uint name_len; int mo ...

  7. Python基础-字符串的使用

    基础知识 字符串解释:字符串是不可变的,所有元素赋值和切片赋值操作都是非法的,属于序列一种(字符串.元组.列表). 一.格式化字符串 (1).format()方法==str.format() 作用:将 ...

  8. 基于appium的app自动化测试框架

    基于appium框架的app自动化测试 App自动化测试主要难点在于环境的搭建,appium完全是基于selenium进行的扩展,所以app测试框架也是基于web测试框架开发的 一.设备连接 (即构建 ...

  9. 15.2,redis发布订阅

    发布publish 订阅subscribe Redis 通过 PUBLISH . SUBSCRIBE 等命令实现了订阅与发布模式. 举例1: qq群的公告,单个发布者,多个收听者 发布/订阅 实验 发 ...

  10. Struts2---环境搭建及包介绍

    导入jar包 jar包下载地址:http://www.apache.org/官网中选择struts,然后点击download下载.将jar包导入到WEB-INF下的lib文件目录下. asm-5.2. ...