Aeroplane chess

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

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

Source

题意:

有一个飞行棋n个格子,刚开始在0这个位置,每次可以扔色子,扔到x则可以移动x格
如果到达的位置>=n则胜利
另外在棋盘上还有m对点x,y表示在位置x可以直接飞行到y
求到达胜利平均的扔色子次数

分析:

期望逆推。

d[i]表示到达 i 的时候还需要几次才能到达n。

初始d[n] = 0; 而d[0]就是所求的答案

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <algorithm>
#define LL __int64
const int maxn = 1e5+;
using namespace std;
double d[maxn];
int c[maxn]; int main()
{
int n, m, i, j;
while(~scanf("%d%d", &n, &m))
{
if(n== && m==) break;
memset(c, -, sizeof(c));
for(i = ; i < m; i++)
{
int a, b;
scanf("%d%d", &a, &b);
c[a] = b;
}
memset(d, , sizeof(d));
d[n] = ;
double t = 1.0/;
for(i = n-; i >= ; i--)
{
if(c[i]==-)
d[i] += 1.0 + d[i+]*t + d[i+]*t+d[i+]*t+d[i+]*t+d[i+]*t+d[i+]*t;
else
d[i] = d[c[i]];
}
printf("%.4f\n", d[]);
}
return ;
}

hdu 4405 Aeroplane chess(简单概率dp 求期望)的更多相关文章

  1. HDU 4405 Aeroplane chess (概率DP求期望)

    题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...

  2. hdu 4405 Aeroplane chess (概率DP)

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

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

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

  4. HDU-4405 Aeroplane chess(概率DP求期望)

    题目大意:一个跳棋游戏,每置一次骰子前进相应的步数.但是有的点可以不用置骰子直接前进,求置骰子次数的平均值. 题目分析:状态很容易定义:dp(i)表示在第 i 个点出发需要置骰子的次数平均值.则状态转 ...

  5. Aeroplane chess(简单概率dp)

    Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz start ...

  6. HDU3853-LOOPS(概率DP求期望)

    LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Su ...

  7. HDU 4405:Aeroplane chess(概率DP入门)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description   Hzz loves ...

  8. HDU 4405 Aeroplane chess 期望dp

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

  9. POJ2096 Collecting Bugs(概率DP,求期望)

    Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...

随机推荐

  1. JavaScript之substring()方法讲解

    定义和用法 substring() 方法用于提取字符串中介于两个指定下标之间的字符. 语法 stringObject.substring(start,stop) 参数 描述 start 必需.一个非负 ...

  2. JavaScript之表单验证讲解

    JavaScript 可用来在数据被送往服务器前对 HTML 表单中的这些输入数据进行验证. JavaScript 表单验证 JavaScript 可用来在数据被送往服务器前对 HTML 表单中的这些 ...

  3. nginx配置解读

    nginx.conf基本配置 ##Start. ##Basic 基础配置 user www www; #运行用户 worker_processes ; #启动进程,通常设置成和cpu的数量相等 wor ...

  4. WSDL相关文档

    http://msdn.microsoft.com/en-us/library/ms996486.aspx http://msdn.microsoft.com/en-us/library/aa4685 ...

  5. HDOJ 1050 Moving Tables

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. wordpress无法安装这个包。: PCLZIP_ERR_MISSING_FILE (-4) : Missing archive file 'C:\WINDOWS\TEMP/wordpress-4.tmp'

    朋友的wp博客好久没管理了,让ytkah帮忙打理一下,进到后台发现版本还是3.9的,那是比较早以前的版本了,早该升级了. 在升级wordpress时出现以下错误: 无法安装这个包: PCLZIP_ER ...

  7. Redis与Memcached的incr/decr差异对比

    目前广泛使用的分布式缓存Redis和Memcached均支持对整数型Value值的增减,对应到具体命令中就是incr和decr命令. incr/decr是原子性操作(memcached 1.2.4及以 ...

  8. (转)Android: NDK编程入门笔记

    转自: http://www.cnblogs.com/hibraincol/archive/2011/05/30/2063847.html 为何要用到NDK? 概括来说主要分为以下几种情况: 1. 代 ...

  9. IDA 使用技巧

    我用的IDA Pro 6.5,把我自己使用ida的一些方法记录,免得自己遗忘 1 .导入符号表 可以像前一篇博客中写的那样,也可以使用File--->LoadFile--->PDB Fil ...

  10. http://linuxme.blog.51cto.com/1850814/372960

    http://linuxme.blog.51cto.com/1850814/372960 http://os.51cto.com/art/201404/435129.htm