我是靠谱客的博主 苗条硬币,这篇文章主要介绍杭电ACM 2048 神、上帝以及老天爷,现在分享给大家,希望可以做个参考。

http://acm.hdu.edu.cn/showproblem.php?pid=2048

利用错排公式和阶乘来做。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream> #include <iomanip> using namespace std; __int64 Fac(int n){ __int64 ans=1; for(int i=1;i<=n;i++){ ans=ans*i; } return ans; }//n的阶乘 int main() { __int64 abc[21]; abc[1]=0; abc[2]=1; for(int i=3;i<=20;i++) abc[i]=(abc[i-1]+abc[i-2])*(i-1); int n; cin>>n; while(n--){ int a; cin>>a; //cout<<"t"<<Fun(a)<<endl<<"t"<<Fac(a)<<endl; double res=1.0*abc[a]/Fac(a)*100; cout<<fixed<<setprecision(2)<<res<<"%"<<endl; } return 0; }


最后

以上就是苗条硬币最近收集整理的关于杭电ACM 2048 神、上帝以及老天爷的全部内容,更多相关杭电ACM内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部