Play the Dice

1341: Play the Dice

Time Limit: 1 Sec   Memory Limit: 64 MB
Submit: 47   Solved: 15
[ Submit][ Status][ Web Board]

Description

There is a dice with N sides, which are numbered from 1,2,...,n and have the equal possibility to show up when one rolls a dice. Each side has an integer Ai on it. Now here is a game that you can roll this dice once, if the i-th side is up, you will get Ai yuan. What's more, some sids of this dice are colored with a special different color. If you turn this side up, you will get once more chance to roll the dice. When you roll the dice for the second time, you still have the opportunity to win money and rolling chance. Now you need to calculate the expectations of money that we get after playing the game once.

Input

Input consists of multiple cases. Each case includes two lines. End with EOF.
The first line is an integer N (2<=N<=200), following with N integers Ai(0<=Ai<200)
The second line is an integer M (0<=M<=N), following with m integers Bi(1<=Bi<=n), which are the numbers of the special sides to get another more chance.

Output

Just a real number which is the expectations of the money one can get, rounded to exact two digits. If you can get unlimited money, print "inf" a line without double quotes.

Sample Input

6 1 2 3 4 5 6
0
4 0 0 0 0
1 3

Sample Output

3.50
0.00

摇色子,要到那一面就得到那一面的钱数,如果要到的数在b[i]中出现过,就表示这一面是比较特殊的一面就还可以再摇一次,问最终得到钱数的期望!

这个题本来以为挺难的,因为如果摇到特殊号,就可以再摇,那么再摇的话有可能再摇到此号,循环往复,无休无止……   就相当于递归,但没有终止条件,不知道什么时候终止,那么怎么办呢?!     如果用递归表示这个题的话,还有一个不合适的地方,递归虽然每次函数名都相同,但是内部的参数变量都是不相同的;而这里的变化确实同步的,

就好比int i=3;   a=(++i)+(++i);    a=5+5=10,而不是9,第一次i自增1变成4,第二个参数i变成5,那么第一个参数也变成5了,这里的变化是同步的!

具体解释参考的:

ans=1/N *(A[B[1]]+ans) + 1/N *(A[B[2]]+ans)  + ...1/N *(A[B[M]]+ans) + 1/N A[k]+....

http://www.cnblogs.com/kuangbin/archive/2013/05/16/3082750.html

是特殊值的多加一个ans,不是的就加本身……

#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int n,m;
int a,b;
double ans;
double sum;
int main()
{
    while( ~scanf("%d",&n) )
    {
        sum=0;
        for(int i=0;i<n;++i)
        {
            scanf("%d",&a);
            sum+=a;
        }
        scanf("%d",&m);
        for(int i=0;i<m;++i)
        {
            scanf("%d",&b);
        }
        if(n==m)cout<<"inf"<<endl;
        else
        {
             ans=sum/(n-m);
            printf("%.2f\n",ans);

        }
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据以下要求编写一个python程序1. Description Ship of Fools is a simple classic dice game. It is played with five standard 6-faced dice by two or more players. - The goal of the game is to gather a 6, a 5 and a 4 (ship, captain and crew) in the mentioned order. - The sum of the two remaining dice (cargo) is preferred as high as possible. The player with the highest cargo score wins the round. Example: - In the first round turn, if a player rolls 6 4 3 3 1 (note we five dice at the beginning), the player can bank the 6 (ship), but the rest needs to be re-rolled since there is no 5. - In the second round turn, if the player rolls 6 5 4 4 (four dice, since the 6 from last turn is banked), the player can bank the 5 (captain) and the 4 (crew). The player has three choices for the remaining 6 and 4. The player can bank both and score 10 points, or re-roll one or two of the dice and hope for a higher score. - In the second round turn, if the player instead rolled 4 4 3 1, all dice needs to be re-rolled since there is no 5.程序需要包含一下几个类.The division of responsibility between the different classes is as follows. - Die: Responsible for handling randomly generated integer values between 1 and 6. - DiceCup: Handles five objects (dice) of class Die. Has the ability to bank and release dice individually. Can also roll dice that are not banked. - ShipOfFoolsGame: Responsible for the game logic and has the ability to play a round of the game resulting in a score. Also has a property that tells what accumulated score results in a winning state, for example 21. - Player: Responsible for the score of the individual player. Has the ability, given a game logic, play a round of a game. The gained score is accumulated in the attribute score. - PlayRoom: Responsible for handling a number of players and a game. Every round the room lets each player play, and afterwards check if any player has reached the winning score.
最新发布
06-02

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值