nyoj1101Oh, my God!错排公式

nyoj1101
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(onenten ).The last tes 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%.
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
using namespace std;
//错排公式 
//https://www.cnblogs.com/c1299401227/p/5349727.html 
int main() {
  int n;
  int count_ = 1;
  double dp[11], dp2[11];
  dp2[0] = dp2[1] = 1, dp2[2] = 2;
  dp[1] = 0, dp[2] = 1;
  for (int i = 3; i <= 10; i++) {
    dp2[i] = dp2[i - 1] * i;
    dp[i] = (i - 1) * (dp[i - 2] + dp[i - 1]);
  }
  while (scanf("%d", &n), n) {
    if (n != 1) printf("Case [%d]: %.2f%%.\n", count_, 100 * (dp[n] / dp2[n]));
    else printf("Case [%d]: 100.00%%.\n", count_);
    count_++;
  }
  return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值