hdoj 1099 Lottery(期望)
2012-03-29 18:13
375 查看
【题目大意】:给出n张不同的牌,每种无限张,问你收集齐n张不同的牌所需的平均次数。
【解题思路】:简单的期望题,假设现在手中有k张不同的牌,则下一张是不同的牌的概率是 (n-k)/n。那么抽到不重复的牌的期望张数是 n/(n-k)...
把n提出来~求E=n*sigema(1/k)(1<=k<=n)
一时大意,求分母的时候没边求边约分,爆longlong了wa了一次,没意识啊。
【代码】:
【解题思路】:简单的期望题,假设现在手中有k张不同的牌,则下一张是不同的牌的概率是 (n-k)/n。那么抽到不重复的牌的期望张数是 n/(n-k)...
把n提出来~求E=n*sigema(1/k)(1<=k<=n)
一时大意,求分母的时候没边求边约分,爆longlong了wa了一次,没意识啊。
【代码】:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <cmath> #include <string> #include <cctype> #include <map> #include <iomanip> using namespace std; #define eps 1e-8 #define pi acos(-1.0) #define inf 1<<30 #define linf 1LL<<60 #define pb push_back #define lc(x) (x << 1) #define rc(x) (x << 1 | 1) #define lowbit(x) (x & (-x)) #define ll long long int n; ll get_len(ll n){ ll len=0; while (n){ n/=10,len++; } return len; } ll GCD(ll a,ll b){ while (b) { ll c; c=a%b,a=b,b=c; } return a; } void solve() { ll tmp=1; for (int i=1; i<=n; i++) tmp=tmp*i/GCD(tmp,i); ll ans=0; for (int i=1; i<=n; i++) ans+=tmp/i; ans*=n; ll gcdtmp; gcdtmp=GCD(ans,tmp); ans=ans/gcdtmp; tmp=tmp/gcdtmp; ll k; k=ans/tmp; ans=ans%tmp; if (ans==0) {cout << k << endl;} else { ll len1,len2; len1=get_len(k); len2=get_len(tmp); for (int i=1; i<=len1+1; i++) cout <<" " ; cout << ans << endl; cout << k << " "; for (int i=1; i<=len2; i++) cout << "-"; cout << endl; for (int i=1; i<=len1+1; i++) cout << " "; cout << tmp << endl; } } int main() { while (~scanf("%d",&n)){ solve(); } return 0; }
相关文章推荐
- HDOJ 1099 Lottery
- hdoj1099 Lottery(简单的数学问题变相考察最小公倍数)
- 【HDOJ】1099 Lottery
- HDU/HDOJ 1099 Lottery
- hdoj 5570 balls 【概率dp 求期望】
- hdu 1099 Lottery 解题分析
- HDOJ 3583 LOOPS(期望DP)
- hdu 1099 Lottery
- HDU 1099 Lottery
- hdoj 4336 card collector(状态压缩dp求数学期望)
- hdoj3853LOOPS【概率dp求期望】
- HDOJ 1145 So you want to be a 2n-aire? 期望DP
- JZOJ3377 【NOI2013模拟】抽奖(lottery) 期望的线性性
- HDU 1099 Lottery (数学问题模拟)
- hdoj 5045 期望dp
- hdoj 5492 Find a path 【dp求解 期望】
- hdu 1099 Lottery
- HDUOJ 1099——Lottery
- hdu 1099 Lottery
- hdu 1099 Lottery