nyoj1101
Oh, my God!
时间限制:1000 ms | 内存限制:65535 KB
难度:2
描述
In order to happy everyone, organizer HRW held anopen up
partythere have specific requirements for this activity is
this:
First of all, all person inthe party will have towritea
note to his name intothe box;Then, after all the note added
is completed, each taking a note fromthe box;Finally, if
made note of your name, then"Congratulations, won the party!"
Oh, my God!
Now tothe question, you can calculate the probability of
this happening?Don't count? Don't you want said by others asa DouBi?! AC it!
输入
Input filecontains several test cases. Each test case consists
ofainteger numbers n onaline(one≤n≤ten ).Thelasttescase
is followed byaline that containsone zeroes. This line
must not be processed.
输出
print thethe probability
See the following example.
样例输入
230
样例输出
Case [1]: 50.00%.
Case [2]: 33.33%.
#include<iostream>#include<algorithm>#include<vector>#include<cstdio>#include<cstring>#include<cstdlib>#include<map>usingnamespacestd;
//错排公式 //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]));
elseprintf("Case [%d]: 100.00%%.\n", count_);
count_++;
}
return0;
}