hdoj 1099 Lottery(期望)
来源:互联网 发布:撩汉 知乎 编辑:程序博客网 时间:2024/05/21 19:26
【题目大意】:给出n张不同的牌,每种无限张,问你收集齐n张不同的牌所需的平均次数。
【解题思路】:简单的期望题,假设现在手中有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 longint 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(期望)
- Lottery Hdoj 1099
- HDU/HDOJ 1099 Lottery
- HDOJ 1099 Lottery
- HDOJ HDU 1099 Lottery
- HDOJ 4405 Aeroplane chess(期望DP)
- HDOJ 3583 LOOPS(期望DP)
- HDOJ 3853 LOOPS(DP期望入门)
- hdu 1099 lottery
- hdu 1099 Lottery
- hdu 1099 Lottery
- hdu 1099 Lottery
- hdu 1099 Lottery
- 【数学】 HDU 1099 Lottery
- HDU ACM 1099 Lottery
- HDU 1099 Lottery 乐透彩
- Lottery (水题)
- Lottery
- java.swing整合
- c# Assembly 类
- 开发第一步之SMTP协议发送邮件,获取手机的详细信息
- java_jdbc整合
- 深入理解Android消息处理系统——Looper、Handler、Thread
- hdoj 1099 Lottery(期望)
- java_线程整合
- java_TCP/UDP整合
- multimedia sync
- 快盘开放API C# 实现
- 2012年初的10个绝对让你惊喜的jQuery插件
- Java如何获得当前目录代码示例
- C++中extern “C”含义深层探索
- lvs+keeplive完整配置文档