Yinyangshi is a famous RPG game on mobile phones.

Kim enjoys collecting cards in this game. Suppose there are n kinds of cards. If you want to get a new card, you need to pay W coins to draw a card. Each time you can only draw one card, all the cards appear randomly with same probability 1/n. Kim can get 1 coin each day. Suppose Kim has 0 coin and no cards on day 0. Every W days, Kim can draw a card with W coins. In this problem ,we define W=(n-1)!.

Now Kim wants to know the expected days he can collect all the n kinds of cards.

Input

The first line an integer T(1 ≤ T ≤ 10). There are T test cases.

The next T lines, each line an integer n. (1≤n≤3000)

Output

For each n, output the expected days to collect all the n kinds of cards, rounded to one decimal place.

Sample Input

4
1
2
5
9

Sample Outpu1.0

3.0
274.0
1026576.0 队友推出公式为
ans = n * ( 1 + 1/2 + 1/3 + … + 1/(n-1) + 1/n );
看到n比较大 然后我就直接上大数了
 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("DATA.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
const int INF = 0x7fffffff;
const int mod = 1e9 + ;
const int maxn = 1e5 + ;
#define MAXN 9999
#define MAXSIZE 10
#define DLEN 4
class BigNum {
private:
int a[(int)1e4 + ]; //可以控制大数的位数
int len; //大数长度
public:
BigNum() {
len = ;
memset(a, , sizeof(a));
} //构造函数
BigNum(const int); //将一个int类型的变量转化为大数
BigNum(const char *); //将一个字符串类型的变量转化为大数
BigNum(const BigNum &); //拷贝构造函数
BigNum &operator=(const BigNum &); //重载赋值运算符,大数之间进行赋值运算 friend istream &operator>>(istream &, BigNum &); //重载输入运算符
friend ostream &operator<<(ostream &, BigNum &); //重载输出运算符 BigNum operator+(const BigNum &) const; //重载加法运算符,两个大数之间的相加运算
BigNum operator-(const BigNum &) const; //重载减法运算符,两个大数之间的相减运算
BigNum operator*(const BigNum &) const; //重载乘法运算符,两个大数之间的相乘运算
BigNum operator/(const int &) const; //重载除法运算符,大数对一个整数进行相除运算 BigNum operator^(const int &) const; //大数的n次方运算
int operator%(const int &) const; //大数对一个int类型的变量进行取模运算
bool operator>(const BigNum &T) const; //大数和另一个大数的大小比较
bool operator>(const int &t) const; //大数和一个int类型的变量的大小比较 void print(); //输出大数
}; BigNum::BigNum(const int b) { //将一个int类型的变量转化为大数
int c, d = b;
len = ;
memset(a, , sizeof(a));
while (d > MAXN) {
c = d - (d / (MAXN + )) * (MAXN + );
d = d / (MAXN + );
a[len++] = c;
}
a[len++] = d;
} BigNum::BigNum(const char *s) { //将一个字符串类型的变量转化为大数
int t, k, index, l, i;
memset(a, , sizeof(a));
l = strlen(s);
len = l / DLEN;
if (l % DLEN)
len++;
index = ;
for (i = l - ; i >= ; i -= DLEN) {
t = ;
k = i - DLEN + ;
if (k < )
k = ;
for (int j = k; j <= i; j++)
t = t * + s[j] - '';
a[index++] = t;
}
} BigNum::BigNum(const BigNum &T) : len(T.len) { //拷贝构造函数
int i;
memset(a, , sizeof(a));
for (i = ; i < len; i++)
a[i] = T.a[i];
} BigNum &BigNum::operator=(const BigNum &n) { //重载赋值运算符,大数之间进行赋值运算
int i;
len = n.len;
memset(a, , sizeof(a));
for (i = ; i < len; i++)
a[i] = n.a[i];
return *this;
} istream &operator>>(istream &in, BigNum &b) { //重载输入运算符
char ch[MAXSIZE * ];
int i = -;
in >> ch;
int l = strlen(ch);
int count = , sum = ;
for (i = l - ; i >= ;) {
sum = ;
int t = ;
for (int j = ; j < && i >= ; j++, i--, t *= ) {
sum += (ch[i] - '') * t;
}
b.a[count] = sum;
count++;
}
b.len = count++;
return in; } ostream &operator<<(ostream &out, BigNum &b) { //重载输出运算符
int i;
cout << b.a[b.len - ];
for (i = b.len - ; i >= ; i--) {
cout.width(DLEN);
cout.fill('');
cout << b.a[i];
}
return out;
} BigNum BigNum::operator+(const BigNum &T) const { //两个大数之间的相加运算
BigNum t(*this);
int i, big; //位数
big = T.len > len ? T.len : len;
for (i = ; i < big; i++) {
t.a[i] += T.a[i];
if (t.a[i] > MAXN) {
t.a[i + ]++;
t.a[i] -= MAXN + ;
}
}
if (t.a[big] != )
t.len = big + ;
else
t.len = big;
return t;
} BigNum BigNum::operator-(const BigNum &T) const { //两个大数之间的相减运算
int i, j, big;
bool flag;
BigNum t1, t2;
if (*this > T) {
t1 = *this;
t2 = T;
flag = ;
} else {
t1 = T;
t2 = *this;
flag = ;
}
big = t1.len;
for (i = ; i < big; i++) {
if (t1.a[i] < t2.a[i]) {
j = i + ;
while (t1.a[j] == )
j++;
t1.a[j--]--;
while (j > i)
t1.a[j--] += MAXN;
t1.a[i] += MAXN + - t2.a[i];
} else
t1.a[i] -= t2.a[i];
}
t1.len = big;
while (t1.a[t1.len - ] == && t1.len > ) {
t1.len--;
big--;
}
if (flag)
t1.a[big - ] = - t1.a[big - ];
return t1;
} BigNum BigNum::operator*(const BigNum &T) const { //两个大数之间的相乘运算
BigNum ret;
int i, j, up;
int temp, temp1;
for (i = ; i < len; i++) {
up = ;
for (j = ; j < T.len; j++) {
temp = a[i] * T.a[j] + ret.a[i + j] + up;
if (temp > MAXN) {
temp1 = temp - temp / (MAXN + ) * (MAXN + );
up = temp / (MAXN + );
ret.a[i + j] = temp1;
} else {
up = ;
ret.a[i + j] = temp;
}
}
if (up != )
ret.a[i + j] = up;
}
ret.len = i + j;
while (ret.a[ret.len - ] == && ret.len > )
ret.len--;
return ret;
} BigNum BigNum::operator/(const int &b) const { //大数对一个整数进行相除运算
BigNum ret;
int i, down = ;
for (i = len - ; i >= ; i--) {
ret.a[i] = (a[i] + down * (MAXN + )) / b;
down = a[i] + down * (MAXN + ) - ret.a[i] * b;
}
ret.len = len;
while (ret.a[ret.len - ] == && ret.len > )
ret.len--;
return ret;
} int BigNum::operator%(const int &b) const { //大数对一个int类型的变量进行取模运算
int i, d = ;
for (i = len - ; i >= ; i--) {
d = ((d * (MAXN + )) % b + a[i]) % b;
}
return d;
} BigNum BigNum::operator^(const int &n) const { //大数的n次方运算
BigNum t, ret();
int i;
if (n < )
exit(-);
if (n == )
return ;
if (n == )
return *this;
int m = n;
while (m > ) {
t = *this;
for (i = ; i << <= m; i <<= ) {
t = t * t;
}
m -= i;
ret = ret * t;
if (m == )
ret = ret * (*this);
}
return ret;
} bool BigNum::operator>(const BigNum &T) const { //大数和另一个大数的大小比较
int ln;
if (len > T.len)
return true;
else if (len == T.len) {
ln = len - ;
while (a[ln] == T.a[ln] && ln >= )
ln--;
if (ln >= && a[ln] > T.a[ln])
return true;
else
return false;
} else
return false;
} bool BigNum::operator>(const int &t) const { //大数和一个int类型的变量的大小比较
BigNum b(t);
return *this > b;
} void BigNum::print() { //输出大数
int i;
cout << a[len - ];
for (i = len - ; i >= ; i--) {
cout.width(DLEN);
cout.fill('');
cout << a[i];
}
//cout << endl;
}
int t, n;
int main() {
sf(t);
while(t--) {
sf(n);
BigNum temp = , ans = ;
for (int i = ; i <= n ; i++) temp = temp * i;
for (int i = ; i <= n ; i++) {
ans=ans+temp/i;
}
ans.print();
printf(".0\n");
}
return ;
}


G - YYS FZU - 2278 数学期望 (大数)的更多相关文章

  1. YYS FZU - 2278 (期望)JAVA

    题目链接: G - YYS FZU - 2278 题目大意: 我们现在想要收集到n个卡片,现在已知抽到每种卡片的概率为1/n,现在每隔(n-1)!天就可以进行一次抽奖,问收集齐所有卡片的期望天数. 具 ...

  2. 数学期望和概率DP题目泛做(为了对应AD的课件)

    题1: Uva 1636 Headshot 题目大意: 给出一个000111序列,注意实际上是环状的.问是0出现的概率大,还是当前是0,下一个还是0的概率大. 问题比较简单,注意比较大小: A/C & ...

  3. 【BZOJ3143】游走(高斯消元,数学期望)

    [BZOJ3143]游走(高斯消元,数学期望) 题面 BZOJ 题解 首先,概率不会直接算... 所以来一个逼近法算概率 这样就可以求出每一条边的概率 随着走的步数的增多,答案越接近 (我卡到\(50 ...

  4. Lecture5_1&5_2.随机变量的数字特征(数学期望、方差、协方差)

    一.数学期望 1.离散型随机变量的数学期望 设X为离散随机变量,其概率分布为:P(X=xk)=pk 若无穷级数$\sum_{k=1}^{+\infty}x_kp_k$绝对收敛 (即满足$\sum_{k ...

  5. UVa 1639 Candy (数学期望+组合数学+高精度存储)

    题意:有两个盒子各有n个糖,每次随机选一个(概率分别为p,1-p),然后吃掉,直到有一次,你打开盒子发现,没糖了! 输入n,p,求另一个盒子里糖的个数的数学期望. 析:先不说这个题多坑,首先要用lon ...

  6. 【整理】简单的数学期望和概率DP

    数学期望 P=Σ每一种状态*对应的概率. 因为不可能枚举完所有的状态,有时也不可能枚举完,比如抛硬币,有可能一直是正面,etc.在没有接触数学期望时看到数学期望的题可能会觉得很阔怕(因为我高中就是这么 ...

  7. uva 11762 数学期望+记忆化搜索

    题目大意:给一个正整数N,每次可以在不超过N的素数中随机选择一个P,如果P是N的约数,则把N变成N/p,否则N不变,问平均情况下需要多少次随机选择,才能把N变成1? 分析:根据数学期望的线性和全期望公 ...

  8. 2019暑期集训第二讲 - 组合数学&概率&数学期望

    A - 容斥原理(CodeForces - 451E) 二进制状态压缩暴力枚举哪几个花选的个数超过了总个数,卢卡斯定理求组合数,容斥原理求答案 可以先把每个花的数量当成无限个,这样就是一个多重集的组合 ...

  9. [BZOJ 3143][HNOI2013]游走(数学期望)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3143 分析: 易得如果知道了每条边经过的数学期望,那就可以贪心着按每条边的期望的大小赋 ...

随机推荐

  1. leetcode-对称二叉树

    对称二叉树     给定一个二叉树,检查它是否是镜像对称的. 例如,二叉树 [1,2,2,3,4,4,3] 是对称的. 1 / \ 2 2 / \ / \ 3 4 4 3 但是下面这个 [1,2,2, ...

  2. token接口的测法

    接口一般都有权限的校验,一般是需要登录后才可以调用 对于接口的认证,一般通过两种方式来实现1.校验用户请求中是否包含某项指定的cookie2.校验用户的请求的header中是否包含某项指定的字段(to ...

  3. 孤荷凌寒自学python第八十一天学习爬取图片1

    孤荷凌寒自学python第八十一天学习爬取图片1 (完整学习过程屏幕记录视频地址在文末) 通过前面十天的学习,我已经基本了解了通过requests模块来与网站服务器进行交互的方法,也知道了Beauti ...

  4. C++字符串拼接和输入

    一 .char类型字符串以空字符结尾 1.以空字符结尾,空字符被写作\0,其ASCII码为0,用来标记字符串的结尾. char dog[4]={'a','b','c','d'}   //不是一个字符串 ...

  5. 词嵌入向量WordEmbedding

    词嵌入向量WordEmbedding的原理和生成方法   WordEmbedding 词嵌入向量(WordEmbedding)是NLP里面一个重要的概念,我们可以利用WordEmbedding将一个单 ...

  6. [知识库:python-tornado]异步调用中的上下文控制Tornado stack context

    异步调用中的上下文控制Tornado stack context https://www.zouyesheng.com/context-in-async-env.html 这篇文章真心不错, 非常透彻 ...

  7. HTMLTestRunner解决UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128)

    其中HTML和数据库都是设置成utf-8格式编码,插入到数据库中是正确的,但是当读取出来的时候就会出错,原因就是python的str默认是ascii编码,和unicode编码冲突,就会报这个标题错误. ...

  8. 如何做好FAE工作及FAE职位发展

    此文较长,是作者对于半导体FAE职业的一些总结,码字不容易,耐心的阅读,欢迎点赞. 曾经认识一位做电源研发的工程师,转行在一家代理商做FAE,做了一年半以后,就提出了离职请求,他老板问他是什么原因,他 ...

  9. 20145214 《Java程序设计》第7周学习总结

    20145214 <Java程序设计>第7周学习总结 教材学习内容总结 时间的度量 格林威治标准时间(GMT),现已不作为标准时间使用,即使标注为GMT(格林威治时间),实际上谈到的的是U ...

  10. C#操作Excel执行分类多条件汇总合并

    之前发了一片模拟合并,详见模拟Excel同一列相同值的单元格合并 在之前的文章中介绍了思想,其中Excel采用的二维数组模拟,今天花了点时间,学习了一下C#操作Excel,实现了类似的效果! 准备 需 ...