题目:

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. SAP BI 常用TCODE

    S.No Tcode Description 1 RSA1 Administrator Work Bench 2 RSA11 Calling up AWB with the IC tree 3 RSA ...

  2. asciinema使用

    asciinema让您轻松记录终端会话,并在终端和网页浏览器中重播它们. 安装最新版本: sapt-get install asciinema 记录你的第一个终端视频: asciinema rec f ...

  3. PHP审计(一)

    一.php中常见的危险函数和审计要点 危险函数(功能过于强大)    参数是否外部可控,有没有正确的过滤. PHP获取外界传入参数是通过下面几个全局函数的形式,所以审计参数传入经常要和下面几个变量打交 ...

  4. RESTful API架构和oauth2.0认证机制(概念版)

    1. 什么是REST REST全称是Representational State Transfer,中文意思是表述(编者注:通常译为表征)性状态转移. 它首次出现在2000年Roy Fielding的 ...

  5. 怎样通过互联网ssh访问家里电脑

    需求:用可以上网的公司windows电脑连接家里的manjaro linux电脑.. 环境情况:公司电脑为内网,通过登录出口服务器连接互联网.家里的电脑也为内网,通过连接无线路由器连接外网.路由器有公 ...

  6. python 获取类中除内置方法外的所有方法名

    #!/usr/bin/env python# !-*- coding:utf-8 -*- class Menu: def __init__(self): pass def updateProject( ...

  7. poj 3087 直接模拟

    题意:意思就是,s1,和s2两堆牌,然后先s2一张再s1,最后会出现一个s12序列,例如s1 AHAH S2 HAHA 然后s12为HAAHHAAH,然后前面一部分给s1,后面一部分给s2,然后再重复 ...

  8. Eclipse字体修改

    第一步: 第二步: 第三步: 第四步: 第五步: 第六步:

  9. 绑定host域名 修改手机hosts域名

    windows: C:\Windows\System32\drivers\etc\hosts # 在这儿输入你需要绑定的 hosts 116.31.72.421129 bro-user.flyme.c ...

  10. Java中的垃圾回收机制&内存管理&内存泄漏

    1. Java在创建对象时,会自动分配内存,并当该对象引用不存在的时候,释放这块内存. 为什么呢? 因为Java中使用被称为垃圾收集器的技术来监视Java程序的运行,当对象不再使用时,就自动释放对象所 ...