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 个点出发需要置骰子的次数平均值.则状态转 ...
随机推荐
- SQLServer外键查询删除信息
SELECT FK.NAME,FK.OBJECT_ID,OBJECT_NAME(FK.PARENT_OBJECT_ID) AS REFERENCETABLENAMEFROM SYS.FOREIGN_K ...
- [已解决]gitee初次使用git clone报错
本文描述的错误按实际出现先后顺序排列,并且附上一些其他可能会出现的问题 错误1: JZKJ@DESKTOP-I7Q9QJ4 MINGW64 ~ $ git clone https://gitee.co ...
- Js图片缩放代码 鼠标滚轮放大缩小 图片向右旋转
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- PAT (Basic Level) Practise (中文)- 1026. 程序运行时间(15)
PAT (Basic Level) Practise (中文)- 1026. 程序运行时间(15) http://www.patest.cn/contests/pat-b-practise/10 ...
- JdbcTemplate类对sql的操作使用
<!--方式一: dbcp 数据源配置,在测试环境使用单连接 --> <bean id="dataSource" class="org.apache.c ...
- 【转】Java重构-策略模式、状态模式、卫语句
前言 当代码中出现多重if-else语句或者switch语句时.弊端之一:如果这样的代码出现在多处,那么一旦出现需求变更,就需要把所有地方的if-else或者switch代码进行更改,要是遗漏了某一处 ...
- windows 下phpstudy 升级mysql版本5.7
今天在导入sql文件的时候遇到了sql执行错误.最后找到原因是因为mysql版本过低,导致出错 原因:在执行sql的时候出现了两次CURRENT_TIMESTAMP ,最后得知在5.7版本之前都是不支 ...
- rom bist scripts
rom bist 的input 有rom_content file .校验rom还坏,主要通过signature比较.signature跟rom content file 一一对应的. rom bis ...
- 一段式fsm
//1-paragraph method to decribe FSM //Describe state transition, state output, state input condition ...
- verilog behaviral modeling -- procedural timing contronls
1.delay control : an expression specifies the time duration between initially encountering the state ...