Aeroplane chess

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

Total Submission(s): 1182    Accepted Submission(s): 802

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
 
题意:从0点出发,掷筛子。筛子掷到几(概率同样)就走几步。当中还有像飞行棋一样的设置,即能够从某一点直接跳到下一点。并且还能够连续跳跃,问你从0点到n的步数的数学期望。

思路:dp[i] 表示眼下走到第i格。距离走到终点的数学期望。递推就可以
前期用dfs重构一下图就能够了。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int maxn = 100000+10;
double dp[maxn];
map<int,int> t;
map<int,int> flight;
int n,m;
void dfs(int sta,int x){
if(t[x]==0){
flight[sta] = x;
}else{
dfs(sta,t[x]);
}
}
void init(){
for(map<int,int>::iterator it = t.begin(); it != t.end(); it++){
dfs(it->first,it->second);
}
}
int main(){ while(cin >> n >> m && n+m){
t.clear();
flight.clear();
while(m--){
int a,b;
scanf("%d%d",&a,&b);
t[a] = b;
}
init();
dp[n] = 0;
for(int i = n-1; i >= 0; i--){
dp[i] = 1;
for(int k = 1; k <= 6; k++){
if(i+k <= n){
if(flight[i+k]==0){
dp[i] += dp[i+k]/6;
}else{
dp[i] += dp[flight[i+k]]/6;
} }
}
}
printf("%.4lf\n",dp[0]); }
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDU4405-Aeroplane chess(可能性DP需求预期)的更多相关文章

  1. UVA 10529 Dumb Bones 可能性dp 需求预期

    主题链接:点击打开链接 题意: 要在一条直线上摆多米诺骨牌. 输入n, l, r 要摆n张排,每次摆下去向左倒的概率是l, 向右倒的概率是r 能够採取最优策略.即能够中间放一段.然后左右两边放一段等, ...

  2. [hdu4405]Aeroplane chess(概率dp)

    题意:某人掷骰子,数轴上前进相应的步数,会有瞬移的情况,求从0到N所需要的期望投掷次数. 解题关键:期望dp的套路解法,一个状态可以转化为6个状态,则该状态的期望,可以由6个状态转化而来.再加上两个状 ...

  3. HDU4405 Aeroplane chess(期望dp)

    题意 抄袭自https://www.cnblogs.com/Paul-Guderian/p/7624039.html 正在玩飞行棋.输入n,m表示飞行棋有n个格子,有m个飞行点,然后输入m对u,v表示 ...

  4. HDU4405 Aeroplane chess (概率DP,转移)

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:在一个1×n的格子上掷色子,从0点出发,掷了多少前进几步,同时有些格点直接相连,即若a,b相连,当落 ...

  5. 【HDU4405】Aeroplane chess [期望DP]

    Aeroplane chess Time Limit: 1 Sec  Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...

  6. hdu4405 Aeroplane chess

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

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

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

  8. HDU 4405 Aeroplane chess 期望dp

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

  9. HDU-4405 Aeroplane chess

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 看了一下这个博客http://kicd.blog.163.com/blog/static/12696191 ...

随机推荐

  1. 返璞归真 asp.net mvc (5) - Action Filter, UpdateModel, ModelBinder, Ajax, Unit Test

    原文:返璞归真 asp.net mvc (5) - Action Filter, UpdateModel, ModelBinder, Ajax, Unit Test [索引页] [源码下载] 返璞归真 ...

  2. POJ 2155 D区段树

    POJ 2155  D区段树 思考:D区段树是每个节点设置一个段树树. 刚開始由于题目是求A[I,J],然后在y查询那直接ans^=Map[i][j]的时候没看懂.后面自己把图画出来了才理解. 由于仅 ...

  3. vpdn详细说明

     VPDN英文为Virtual Private Dial-up Networks,又称为虚拟专用拨号网,是VPN业务的一种,是基于拨号用户的虚拟专用拨号网业务. 中文名 虚拟专用拨号网业务 外文名 ...

  4. CMSIS标准

    CMSIS 标准(Cortex Microcontroller Software Interface Standard) ,翻译过来是"ARM Cortex™ 微控制器软件接口标准" ...

  5. Bug记录:微博的Java SDK返回经纬度错误

    现象:美国的坐标点可能会定位到西藏地区-后发现原来负经度经解析后,均变成正的! 源码: private void getGeoInfo(String geo) { StringBuffer value ...

  6. Eamcs ditaa基于字符图形产生的图像上

    ditta和artist mode这是一个好兄弟.artist mode帮我创建一个字符模式速度,ditta是java计划,字符图形可被读取,并生成图像. ditta网站:http://ditaa.s ...

  7. 【Hibernate学习】 ——ORM(三)

    前面几种关系我们曾经就常常常使用,对于继承我们也并不陌生,常常接触的类与类之间的继承用extendskeyword,那么在表与表的关系中怎样表示呢?以下我们来讲继承映射. 继承有三种实现的策略,单表继 ...

  8. 对LevelDB的“升级版”存储引擎RocksDB的调研成果

    Google的leveldb是个非常优秀的存储引擎.但还是有一些不尽人意的地方,比方leveldb不支持多线程合并.对key范围查找的支持还非常easy,未做优化措施,等等.而Facebook的Roc ...

  9. 三思考,实现自己定义404页:Tomcat、SpringMVC精确匹配、重写DispatchServlet

    第1种方式:Tomcat直接处理 web.xml <error-page> <error-code>404</error-code> <location> ...

  10. JSP通用7动作命令

    JSP通用7动作命令 1.jsp:forward指令    运行页面转向.将请求处理转发到下一个页面 2.jsp:param指令    用于传递參数 3.jsp:include指令    用于动态引入 ...