Oh, my God!
时间限制:
1000 ms | 内存限制:
65535 KB
难度:
2
-
描述
-
In order to happy everyone, organizer HRW held an open up partythere have specific requirements for this activity is this:
First of all, all person in the party will have to write a note to his name into the box;Then, after all the note added is completed, each taking a note from the box;Finally, if made note of your name, then "Congratulations, won the party!"
Oh, my God!
Now to the question, you can calculate the probability of this happening?Don't count? Don't you want said by others as a DouBi?! AC it!-
输入
- Input file contains several test cases. Each test case consists of a integer numbers n on a line(one≤n≤ten ).The last test case is followed by a line that contains one zeroes. This line must not be processed. 输出
-
print the the probability
See the following example.
样例输入
-
2 3 0
样例输出
-
Case [1]: 50.00%. Case [2]: 33.33%.
提示
- 要用到错排公式,计算所有人都抽到自己名字的概率
!!!!!!!!!!!!
题意有问题,本来说的是要求某个人抽到自己名字的概率,但是,给出的提示包括最后通过的代码都是都是考察的错排公式................
然而....特判 1 的时候 竟然要特判出 100%!!!否则不能过..
错排不多说,题意就是坑......一直没明白到底让求什么概率........
#include<stdio.h>
long long x[30],y[30];//打表
void db()
{
x[0]=x[1]=y[2]=1;x[2]=2;y[1]=0;
for(int i=3;i<20;++i)
{
x[i]=x[i-1]*i;
y[i]=(i-1)*(y[i-1]+y[i-2]);
}
}
int main()
{
db();int n,t=0;
while(scanf("%d",&n),n)
{
double p=y[n]*1.0/x[n]*100.0;
if(n==1)//无语的特判!!
{
p=100;
}
printf("Case [%d]: %.2lf%%.\n",++t,p);
}
return 0;
}