|
应该说是一个纯数学的题目,考察错排的概率。
#include <stdio.h> #define DEBUG 1 int main() { #if DEBUG freopen("C:\\Documents and Settings\\Administrator\\桌面\\in.in","r",stdin) ; freopen("C:\\Documents and Settings\\Administrator\\桌面\\out.out","w",stdout) ; #endif __int64 i, n, sets, s, fenmu ; double p, temp ; scanf("%I64d", &sets ) ; while( sets-- ){ scanf("%I64d", &n ) ; p = 1 ; s = 1 ; fenmu = 1 ; for( i=1; i<=n; ++i ){ s *= -1 ; fenmu *= i ; p += s/(double)fenmu ; } printf("%.2lf%%\n", 100*p ) ; } }
|