uva10288:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1229

题意:有一种盒子,盒子一面会随机放一种卡片,现在要集齐n种卡片,问要买多少个盒子。

题解:假如说n==2,那么第一次买,肯定可以得到一种新的卡片,第二次买得到新的卡片的概率是1/2,也就是说你那买2包才能得到新的卡片,所以期望值是1+2==3;如果n==3的话,第一次概率是1,第二次是2/3,也就是说第二次要买3/2包才能得到一种新的卡片,第三次是1/3,所以要买3包,所以总的期望是1+3/2+3;一次类推,可以得到期望:n/1+n/2+n/3+.....+n/n.还有题目中的输出格式,用log(a)/log(10)+1就可以得到a的位数。还有uva用的是lld,不是I64d

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
#include<cmath>
using namespace std;
long long n,temp,a,b,ans;
long long gcd(long long a, long long b){
if(b==)
return a;
return gcd(b,a%b);
} int main(){
while(~scanf("%lld",&n)){
a=;b=;ans=;
for(int i=;i<=n;i++){
a=a*i+b;
b=b*i;
temp=gcd(a,b);
a/=temp;
b/=temp;
}
a*=n;
temp=gcd(a,b);
a/=temp;
b/=temp;
ans=a/b;
a=a%b;
temp=gcd(a,b);
a/=temp;
b/=temp;
int m,t;
int s=(int)(log(b)/log()+);
m=t=(int)(log(ans)/log()+);
if(a==)
printf("%lld\n",ans);
else{
while(t--)printf(" ");
printf("%lld\n",a);
printf("%lld ",ans);
while(s--)printf("-");
printf("\n");
while(m--)printf(" ");
printf("%lld\n",b);
} }
}

Coupons的更多相关文章

  1. codeforces754D Fedor and coupons

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  2. codeforces 754D. Fedor and coupons

    D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  3. Codeforces 390Div2-754D. Fedor and coupons(贪心+优先队列)

    D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  4. Uva 10288 Coupons

    Description Coupons in cereal boxes are numbered \(1\) to \(n\), and a set of one of each is require ...

  5. Coupons and Discounts

    Coupons and Discounts time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. Codeforces 376B. Coupons and Discounts

    B. Coupons and Discounts time limit per test 1 second memory limit per test 256 megabytes input stan ...

  7. 最新亚马逊 Coupons 功能设置教程完整攻略!

    最新亚马逊 Coupons 功能设置教程完整攻略! http://m.cifnews.com/app/postsinfo/18479 亚马逊总是有新的创意,新的功能.最近讨论很火的,就是这个 Coup ...

  8. [POJ2625][UVA10288]Coupons

    Description Coupons in cereal boxes are numbered 1 to n, and a set of one of each is required for a ...

  9. USACO 2012 Feb Cow Coupons

    2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec Memory Limit: 128 MB Submit: 349 Solved: 181 [Su ...

  10. 2590: [Usaco2012 Feb]Cow Coupons

    2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 306  Solved: 154[Su ...

随机推荐

  1. Solr与Tomcat的整合

    solr与tomcat整合有两种方法: 方法一:其整合步骤如下: 1.将solr中的example中的solr拷贝到要作为服务器的位置(我当前创建的目录为D:\Develop\solr\home) 2 ...

  2. git如何clone所有的远程分支

    问题: 文/赖忠标 周末在家里改了下代码,新建了个angular版本的分支,然后push到coding.net上面了. 今天,到公司却不知道怎么拉取这个angular分支到公司的电脑上面.如下图(1) ...

  3. MyBatis架构图

    MyBatis架构 MyBatis依赖的jar不多,而且代码行数也没多少,其中使用了大量的设计模式,值得好好学习.下图是MyBatis的一张架构图,来自Java框架篇—Mybatis 入门. Myba ...

  4. [PWA] 15. Using The IDB Cache And Display Entries

    We want to use IDB to store the wittr messages. The logic is when the page start: service worker wil ...

  5. 多线程下的NSOperation和NSOperationQueue的使用

    多线程下的NSOperation和NSOperationQueue的使用 NSOperation和NSOperationQueue的介绍: NSOperation是Cocoa中的一个抽象类,用来封装单 ...

  6. android strings.xml转义字符, 注意细节解决(转)

    XML转义字符 以下为XML标志符的数字和字符串转义符 "     (" 或 ") '     (' 或 &apos;) &     (& 或 & ...

  7. Java基础知识强化19:Java中switch分支语句

    java中switch语句: 这里expression控制表达式的数据类型只能是byte.short.char.int四种整型类型和枚举类型,不能是boolean类型: Java7(1.7)改进了sw ...

  8. Activity 【生命周期】

    不同情况下的回调 我们打开应用时先后调用了onCreate()->onStart()->onResume 当我们按BACK键时,我们这个应用程序将结束,这时候我们将先后调用onPause( ...

  9. DataTable去重复方法

    //去掉重复行 DataTable table=new DataTable(); DataView dv = table.DefaultView; table = dv.ToTable(true, n ...

  10. UIScrollView 之图片缩放

    UIScrollView 之图片缩放 有些时候,我们可能要对某些内容进行手势缩放,如下图所示 UIScrollView不仅能滚动显示大量内容,还能对其内容进行缩放处理 也就是说,要完成缩放功能的话,只 ...