题目描述:一个骰子有n面,每面朝上的概率相同,并且每一面上面都有一个数字,其中有m面是彩色的,代表掷到彩色面的时还可以继续掷下去,问最终掷得的数字的期望是多少?
using System;
using System.Linq;
public class VJ
{
static int Main()
{
process();
Console.ReadLine();
return 0;
}
static void process()
{
string str;
int[] arr;
int m,sum;
while((str=Console.ReadLine())!=null)
{
arr=Array.ConvertAll<string , int>(str.Split(‘ ‘) , r => int.Parse(r));
m=Convert.ToInt32((str=Console.ReadLine())[0].ToString());
sum=(from int r in arr select r).Sum()-arr[0];
if(m==0) Console.WriteLine("{0:0.00}" , (double)sum/(double)arr[0]);
else if(m==arr[0]) Console.WriteLine("inf");
else Console.WriteLine("{0:0.00}" , (double)sum/(double)(arr[0]-m));
}
}
}
Hdu 4386 Play the Dice 解题报告,布布扣,bubuko.com
原文:http://www.cnblogs.com/au-xiaotian/p/3841046.html