Coupons
题意:有一种盒子,盒子一面会随机放一种卡片,现在要集齐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的更多相关文章
- codeforces754D Fedor and coupons
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- codeforces 754D. Fedor and coupons
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 390Div2-754D. Fedor and coupons(贪心+优先队列)
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Uva 10288 Coupons
Description Coupons in cereal boxes are numbered \(1\) to \(n\), and a set of one of each is require ...
- Coupons and Discounts
Coupons and Discounts time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces 376B. Coupons and Discounts
B. Coupons and Discounts time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 最新亚马逊 Coupons 功能设置教程完整攻略!
最新亚马逊 Coupons 功能设置教程完整攻略! http://m.cifnews.com/app/postsinfo/18479 亚马逊总是有新的创意,新的功能.最近讨论很火的,就是这个 Coup ...
- [POJ2625][UVA10288]Coupons
Description Coupons in cereal boxes are numbered 1 to n, and a set of one of each is required for a ...
- USACO 2012 Feb Cow Coupons
2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec Memory Limit: 128 MB Submit: 349 Solved: 181 [Su ...
- 2590: [Usaco2012 Feb]Cow Coupons
2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 306 Solved: 154[Su ...
随机推荐
- DCL双检查锁机制实现的线程安全的单例模式
public class MyObject { private volatile static MyObject myObject; private MyObject(){} public stati ...
- 使用Linux的命令行工具做简单的文本分析
Basic Text Analysis with Command Line Tools in Linux | William J Turkel 这篇文章非常清楚的介绍了如何使用Linux的命令行工具进 ...
- 1002 A + B Problem II [ACM刷题]
这一段时间一直都在刷OJ,这里建一个博客合集,用以记录和分享算法学习的进程. github传送门:https://github.com/haoyuanliu/Online_Judge/tree/mas ...
- 批量更新数据小心SQL触发器的陷阱
批量更新数据时候,Inserted和Deleted临时表也是批量的,但触发器只会调用执行一次!两个概念千万不要弄混淆! 错误的理解:例如:创建在A表上创建了一个Update触发器,里面写的是Updat ...
- [转]Android实现计时与倒计时(限时抢购)的几种方法
在购物网站的促销活动中一般都有倒计时限制购物时间或者折扣的时间,这些都是如何实现的呢? 在一个安卓客户端项目中恰好遇到了类似的问题,一开始使用的是Timer与 TimerTask, 虽然此方法通用,但 ...
- Eclipse Python配置
Macbook上面安装pydev后,发现新建project后并没有PyDev的选项.在官网上搜索后发现是JDK版本太久.上Oracle官网下载了最新JDK(url: http://www.oracle ...
- tomcat URL简写案例:模拟站点www.baidu.com的訪问
tomcat URL简写案例:模拟站点 * 实际URL:http://www.baidu.com:8080/myweb/1.html * 实际位置:F:\mywebapps\myweb\1.htm ...
- IOS 获取wifi的SSID
#import <SystemConfiguration/CaptiveNetwork.h> - (NSString *)currentWifiSSID { // Does not wor ...
- Linux开发工具之gcc
一.gcc入门(上) 1.gcc相关概念 gcc(GNU C Compiler)编译器,最初支持C语言,现已支持C.C++.Java.Pascal.Ada.COBOL语言等:支持多种硬件平台: ...
- 2015 UESTC Winter Training #10【Northeastern Europe 2009】
2015 UESTC Winter Training #10 Northeastern Europe 2009 最近集训都不在状态啊,嘛,上午一直在练车,比赛时也是刚吃过午饭,状态不好也难免,下次比赛 ...