http://acm.hdu.edu.cn/showproblem.php?pid=4405

看了一下这个博客http://kicd.blog.163.com/blog/static/126961911200910168335852/

Aeroplane chess

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

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个方程,回带一下就行。e[n]=0,所有标号i大于n的期望值e[i]也为0.
比如n=3,m=0
所列方程为e[0]=1/6e[1]+1/6e[2]+1/6e[3]+1
                  e[1]=1/6e[2]+1/6e[3]+1
                  e[2]=1/6e[3]+1
                  e[3]=0
从0这个点可以到1,2,3,4,5,6这几个位置,由于大于等于3游戏结束,不会再有期望的投色子次数了,所以跳到3和大于3的格子里期望值也就都是0了。
所以我们列出n个方程后直接回带就能把e[0]求出来。如e[3]=0可以求出e[2]=1,已知了e[2]和e[3]就可以求出e[1],进而求出e[0].
解答:
如果可以飞的话 就是e[a]的期望等于e[b]的期望,a<b;
不可以的话就:e[i]=1.0/6*(e[i+1]+e[i+2]+e[i+3]+e[i+4]+e[i+5]+e[i+6])+1;
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int f[];
double e[];
int main()
{
int i,a,b,n,m;
while(~scanf("%d%d",&n,&m))
{
if(n==&&m==)
break;
memset(f,,sizeof(f));
memset(e,,sizeof(e));
for(i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
f[a]=b;
}
e[n]=;
for(i=n-;i>=;i--)
{
if(f[i]!=)
e[i]=e[f[i]];
else
e[i]=1.0/*(e[i+]+e[i+]+e[i+]+e[i+]+e[i+]+e[i+])+;
}
printf("%.4lf\n",e[]);
}
return ;
}

 
 

HDU-4405 Aeroplane chess的更多相关文章

  1. HDU 4405 Aeroplane chess 期望dp

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

  2. hdu 4405 Aeroplane chess(简单概率dp 求期望)

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

  3. hdu 4405 Aeroplane chess (概率DP)

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

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

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

  5. [ACM] hdu 4405 Aeroplane chess (概率DP)

    Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...

  6. 【刷题】HDU 4405 Aeroplane chess

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

  7. HDU 4405 Aeroplane chess 概率DP 难度:0

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...

  8. HDU 4405 Aeroplane chess(期望)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:从0走到n,每次走之前掷一次筛子,掷出几点就向前走几点,走到大于等于n的地方就停止.但是, ...

  9. HDU 4405 Aeroplane chess:期望dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意: 你在下简化版飞行棋... 棋盘为一个线段,长度为n. 上面有m对传送门,可以直接将你从a ...

  10. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

随机推荐

  1. .net单元测试——解除依赖

    最近在看.net单元测试艺术,我也喜欢单元测试,这里写一下如何在测试中解除对象间的依赖. 假如有这样的一个需求,当用户登陆时,我需要对用户名和密码进行验证,然后再将用户名写入日志中. public c ...

  2. .NET性能优化方面的总结

    从2004年底开始接触C#到现在也有2年多的时间了,因为有C++方面的基础,对于C#,我习惯于与C++对比.现在总结一些.NET方面的性能优化方面的经验,算是对这两年多的.NET工作经历的总结.    ...

  3. 看es6 字符串新方法有感

    'x'.repeat(3) // "xxx" 'hello'.repeat(2) // "hellohello" 'na'.repeat(0) // " ...

  4. 十进制和n进制的转换(10进制转换为36进制)

    答案如下: void Convert() { map<int ,string> maps; maps[0]="0"; maps[1]="1"; ma ...

  5. VC皮肤库之duilib

    首先是个国产的开源 的,directui 界面库,开放,共享,惠众,共赢,遵循bsd协议,可以免费用于商业项目,目前支持Windows 32 .Window CE.Mobile等平台. Duilib ...

  6. Sevlet局部变量初始化

    //java 代码部分package com.servlet; import java.io.IOException; import java.io.PrintWriter; import java. ...

  7. WPF实现导航的几种方式

    下面是展示的是几种导航方式: 我们来具体看下xaml文件 <Page x:Class="WPF实现Navigation.Page1" xmlns="http://s ...

  8. C# 下载资源

    //创建一个初始化请求对象 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://wwww.b ...

  9. FutureTask源码解读

    import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.ut ...

  10. cygwin使用

    Cygwin是一个在windows平台上运行的类UNIX模拟环境,是cygnus solutions公司开发的自由软件(该公司开发的著名工具还有eCos,不过现已被Redhat收购). 它对于学习UN ...