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. 在一个字符串中找到第一个只出现一次的字符。如输入abaccdeff,则输出b

    偶然在群里看到这个小题, 就用python做了做. 思路就是建一个够大的列表并初始化,把每个字符的asc码作为下标,存到列表里, 然后该位置的值就存字母的出现次数, 最后再迭代原字符串并判断列表值是否 ...

  2. C++ 求阶乘 四种方法

    来总结下求阶乘的各种方法哈. 写在最前:①各个代码仅仅是提供了求阶乘的思路,以便在实际须要时再来编码,代码并不健壮!②各个程序都在1到10内測试正确. 代码一: #include<iostrea ...

  3. HDU 1548 A strange lift 搜索

    A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  4. Hibernate知识点总结

    Hibernate配置二级缓存:  --- 使用EhCache 1.hibernate.cfg.xml中配置二级缓存 <hibernate-configuration>   <ses ...

  5. 内存管理概述、内存分配与释放、地址映射机制(mm_struct, vm_area_struct)、malloc/free 的实现

    http://blog.csdn.net/pi9nc/article/details/23334659 注:本分类下文章大多整理自<深入分析linux内核源代码>一书,另有参考其他一些资料 ...

  6. Java基础知识强化之IO流笔记06:有return的情况下try catch finally的执行顺序

    1. 给出结论: (1)不管有木有出现异常,finally块中代码都会执行:(2)当try和catch中有return时,finally仍然会执行:(3)finally是在return后面的表达式运算 ...

  7. 什么是AAC音频格式 AAC-LC 和 AAC-HE的区别是什么

    Advanced Audio Coding(高级音频解码),是一种由MPEG-4标准定义的有损音频压缩格式,由Fraunhofer发展,Dolby, Sony和AT&T是主要的贡献者. 在使用 ...

  8. JAVA 读取pdf文件

    第一个路口action /* * wuhan syspro author zhangrui 2010/08/23 */ package jp.co.syspro.poo.action; import ...

  9. J2EE初探

    J2EE概述 3层结构 4层模型 13项核心技术 J2EE容器 J2EE的优势与缺陷   J2EE概述 Java 2平台有3个版本,分别是适用于小型设备和智能卡的Java 2平台Micro版(Java ...

  10. Android中的缓存机制与实现

    分步阅读 Android开发本质上就是手机和互联网中的web服务器之间进行通信,就必然需要从服务端获取数据,而反复通过网络获取数据是比较耗时的,特别是访问比较多的时候,会极大影响了性能,Android ...