HDU 4405 Aeroplane chess (简单期望)
来源:互联网 发布:js表格分页插件 编辑:程序博客网 时间:2024/06/13 23:14
Aeroplane chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 361 Accepted Submission(s): 255
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.
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.
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
2012 ACM/ICPC Asia Regional Jinhua Online
Recommend
zhoujiaqi2010
本题题意:数轴上有N+1个点(编号0~N),一个人玩游戏,从0出发,当到达N或大于N的点则游戏结束。每次行动掷骰子一次,骰子编号1-6,掷到多少就向前走几步,这个数轴上还有些特殊点,这些点类似飞行棋中的飞行点,只要到达这些点就可以直接飞到给定点。求总共投掷骰子次数的期望。
思路:水题,如果有飞机 那么dp[x] = dp[y]就好了, 没有飞机模拟骰子就好了
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#include <vector>using namespace std;const int maxn = 1e5 + 10;double dp[maxn];int book[maxn];vector<int> v[maxn];int main(){ int n, m; while(~scanf("%d%d", &n, &m), n+m) { int a, b; memset(book, 0, sizeof(book)); memset(dp, 0, sizeof(dp)); for(int i = 0; i <= n; i++) v[i].clear(); for(int i = 1; i <= m; i++) { scanf("%d%d", &a, &b); v[b].push_back(a); } for(int i = n; i >= 0; i--) { if(book[i] && !v[i].size()) continue; if(book[i] && v[i].size()) { for(int j = 0; j < v[i].size(); j++) dp[v[i][j]] = dp[i], book[v[i][j]] = 1; continue; } for(int k = 1; k <= 6; k++) { if(i + k <= n) dp[i] += dp[i+k]/6.0; } if(i != n) dp[i] += 1.0; if(v[i].size()) { for(int j = 0; j < v[i].size(); j++) { dp[v[i][j]] = dp[i], book[v[i][j]] = 1; } } }// for(int i = 0; i <= n; i++)// {// printf("%d : %.4f\n", i, dp[i]);// } printf("%.4f\n", dp[0]); } return 0;}
0 0
- HDU 4405 Aeroplane chess (简单期望)
- HDU 4405 Aeroplane chess(期望)
- HDU 4405 Aeroplane chess(期望DP)
- hdu 4405 Aeroplane chess(期望)
- 简单概率dp(期望)-hdu-4405-Aeroplane chess
- hdu 4405 Aeroplane chess(很水的期望DP)
- HDU 4405 Aeroplane chess (概率DP求期望)
- HDU 4405 - Aeroplane chess (概率DP 求期望)
- hdu 4405 Aeroplane chess (概率DP+求期望)
- HDU 4405 Aeroplane chess 概率dp 求期望(入门)
- hdu 4405 Aeroplane chess (概率与期望)
- 概率与期望 HDU 4405 Aeroplane chess(飞行棋)
- hdu 4405 Aeroplane chess(全期望公式)
- HDU 4405 Aeroplane chess(全期望公式-概率dp)
- HDU 4405 Aeroplane chess (概率DP & 期望)
- HDU 4405 Aeroplane chess (概率-期望DP)【模板】
- HDU 4405 Aeroplane chess(概率DP求期望)
- 【数学期望】hdu 4405 Aeroplane chess
- scala基础——控制结构和函数
- ACM1008玛雅历 剖析
- ZJOI2017游记(雾)
- transform-style: preserve-3d和 perspective透视
- JZOJ 3.25 1419——【汕头市选2012初中组】排序(sort)
- HDU 4405 Aeroplane chess (简单期望)
- Android RecycleView 实现单选列表 并解决View复用导致错乱问题
- sql 基本语法整理
- ScrollView属性总结
- 如何编辑验证码
- LeetCode Algorithms 8. String to Integer (atoi) 题解
- APP界面设计流程和APP产品设计流程知识汇总
- BMS工作
- PHP的echo 和 print 区别: