【刷题】HDU 4405 Aeroplane chess
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
Description(CHN)
在一个 \(1*n\) 的格子上掷色子,从 \(0\) 点出发,掷了多少前进几步,同时有些格点直接相连,即若 \(a\) ,\(b\) 相连,当落到 \(a\) 点时直接飞向 \(b\) 点。求走到 \(n\) 或超出 \(n\) 期望掷色子次数
\(n≤100000\)
Solution
期望倒推
设 \(f[i]\) 表示当前到达第 \(i\) 号点,距离游戏结束的期望是多少
显然,\(f[n]=f[n+1]=...=f[n+5]=0\)
然后反着枚举 \(i\) ,如果当前点有直通机,就直接等于直通的那个点的期望
否则,枚举这一次骰子的点数,\(f[i]=\sum_{x=1}^6\frac{f[i+x]+1}{6}\)
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int MAXN=100000+10;
int n,m,fly[MAXN];
db f[MAXN];
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(!n&&!m)break;
memset(fly,-1,sizeof(fly));
for(register int i=1;i<=m;++i)
{
int u,v;read(u);read(v);
fly[u]=v;
}
for(register int i=0;i<=n+5;++i)f[i]=0.0;
for(register int i=n-1;i>=0;--i)
if(!(~fly[i]))
for(register int x=1;x<=6;++x)f[i]+=f[i+x]/6.0+1/6.0;
else f[i]=f[fly[i]];
printf("%.4f\n",f[0]);
}
return 0;
}
【刷题】HDU 4405 Aeroplane chess的更多相关文章
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- hdu 4405 Aeroplane chess(简单概率dp 求期望)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4405 Aeroplane chess(概率+dp)
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+ grids labeled to ...
- [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
http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...
- HDU 4405 Aeroplane chess(期望)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:从0走到n,每次走之前掷一次筛子,掷出几点就向前走几点,走到大于等于n的地方就停止.但是, ...
- HDU 4405 Aeroplane chess:期望dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意: 你在下简化版飞行棋... 棋盘为一个线段,长度为n. 上面有m对传送门,可以直接将你从a ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
随机推荐
- CF 741 D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths http://codeforces.com/problemset/probl ...
- 算法------------数组----------------两个数组的交集 II
给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2,2] 示例 2: 输入: nums1 = [4,9,5 ...
- 虚拟机ubuntu使用串口
1. 电脑的串口默认是在windows系统上,需要把串口转到ubuntu上面,按照下面的步骤先 2. 找到需要使用的串口 3. 在VMWARE里面连接该串口 或者使用方法 4. 成功之后,检查一下ls ...
- 海思NB-IOT死机问题解决记录
1. 首先抓下LOG的信息,这个应该是MCU到NB的数据 2. 看下NB到MCU的数据 3. 总结起来,只看到了NB模块的启动,似乎AT指令,肯本没收到.测试中确实出现了复位,但是不清楚是发送的AT指 ...
- hdu1069Monkey and Banana(动态规划)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- PHP使用Redis消息队列
1.redis安装 参考:菜鸟教程http://www.runoob.com/redis/redis-install.html 2.安装php的redis扩展 1)phpinfo()查看php版本信息 ...
- 破解IDEA注册码,设置 license server一直有效不过期
破解的详细过程: 1.从下面地址下载一个jar包,名称是 JetbrainsCrack-2.10-release-enc.jar 下载地址是http://idea.lanyus.com/,进去之后点 ...
- 第七模块:项目实战一 第1章 项目实战:CRM客户关系管理系统开发
01-crm介绍 02-权限系统介绍 03-第一版表结构设计 04-第二版表结构设计 05-orm中创建表结构 06-销售管理系统业务 07-销售管理系统权限信息录入 08-快速实现简单的权限控制的设 ...
- sqlserver错误126解决方法
是不是很尴尬! 华丽的分割线下便是解决方法: 1.打开sqlserver配置管理器. 2.选择sqlserver网络配置,并禁用VIA协议确定保存. 3.在服务里面启动[SQL Server (SQL ...
- 【转】: 《江湖X》开发笔谈 - 热更新框架
前言 大家好,我们这期继续借着我们工作室正在运营的在线游戏<江湖X>来谈一下热更新机制以及我们的理解和解决方案.这里先简单的介绍一下热更新的概念,熟悉这部分的朋友可以跳过,直接看我们的方案 ...