当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3756:Chess Game

题目描述

There is a kind of chessboard-game which should be played with pure luck. It is always welcomed by children and maybe some teenagers enjoy killing-time with it. The rules of the game are easy to understand. Totally there are N grids on a chessboard with numeric order. The players start their journeys at grid 0. At the beginning of each round, the player will roll a dice to decide how many steps he will go forward. After he has arrived at the target place, he may found some instructions to follow: he might be told to go forward several steps, or to go backward several steps, or he would be asked to have a rest, with no right to roll the dice in the next round. The target of such game is quite simple, too: try to be the first player who reaches the goal!

For university students, such games looks too simple, or sometimes naïve, but now this game has one more application—to evaluate one's RP (which is a very important property in our daily life)! In order to decide whether you have high RP or not, it is quite essential to decide the expectation number of the rounds you can reach the goal, and that is what you should do.

To remove ambiguities, we made the following assumptions:

1) Only one instruction should be followed and there is no chain-effect for instructions. For example, if you followed the instruction on grid 15 and go 3 steps forward to grid 18, then you will wait at grid 18 until the next round begins no matter what instructions are in grid 18.

2) One can reach the goal if and only if he arrived exactly on grid N and redundant steps will change directions. For example, the goal is at grid 100 and you are now standing in grid 98, if you roll the dice and get 5 points, then your finally position is in grid 97(98->99->100->99->98->97) if there is no instructions at grid 97. The same rule is adapted to grid 0.

3) The dice is a cube and the probability of getting every kind of points from 1 to 6 is equal to 1/6.

4) There are 3 kind of instructions, go forward for 1 to 6 steps/go backward for 1 to 6 steps/no dice rolling in the next round.

Input the information of the chessboard and you should output the expectation number of the rounds you can reach the goal.

输入解释

The first line of the input contains one integer N(N ≤ 100), the number of grids on the chessboard (so that there are N+1 grids totally).

The next line contains one integer Nf, the number of "go forward" instructions. Next Nf lines contain two integers each. The first integer stands for the number of grid having the instruction and the second integer stand for the number of steps to go forward.

Following line contains one integer Nb, the number of "go backward" instructions. The formats of next Nb lines are similar as what mentioned above.

The next line contains one integer Ns, the number of "stop" instructions. Next Ns lines contain one integer each, which stand for the number of grid having the instruction.

输出解释

Output contains only one real number, representing the expectation number of the rounds to reach the goal. The answer should be rounded to 0.01. If it is impossible to reach the goal, print "Impossible" instead.

输入样例
10
1
9 2
2
2 4
4 4
1
5
输出样例
8.81

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3756

最后修改于 2020-10-29T07:10:21+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536