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. Unity3D 画线插件 Vectrosity 画一个一直循环的正弦函数曲线

    直接贴代码 public Material myMaterisl; float fx;//曲线最左边的X坐标 float fy;//曲线趋于直线时y轴坐标 float fyMax = 0f;//曲线最 ...

  2. today's learning of english 1

    1.curriculum    必修课 主修课 2.sought       seek的过去式 3.blessed with a wonderful marriage   有个幸福美满的婚姻 4.al ...

  3. 面向新手的Webserver搭建(一)——IIS的搭建

    非常多童鞋说自己是做移动开发的,想挂个简单的Web API,但是server又不会搭,这样一来測试就成了问题.看看网上的教程.发现略难懂,并且大多是一个转一个,没价值,所以干脆写几篇文章讲讲简单的We ...

  4. [资源分享]神州数码 思科 UCS 虚拟化培训资料

    神州数码 思科 UCS 虚拟化培训资料   点击文件名下载 UCS统一计算平台=.pdf 云计算Demo实验教材_Nexus 5K2K实验.pdf 云计算数据中心架构与技术.pdf 云计算数据中心虚拟 ...

  5. poj2993 poj2669

    扯淡题. 2993 #include <iostream> #include <stdio.h> #include <string> #include <st ...

  6. SPOJ 3937 - Wooden Sticks 最长上升子序列LIS

    给了n个(n<=5000)木棍的长度hi与宽度wi(均小于10000),现在机器要打磨这些木棍,如果相邻连个木棍hi<=hj并且wi<=wj就不需要调整机器,问如何排序使得机器调整的 ...

  7. hash练习

    /* poj 1200 Crazy Search 字符串hash O(n)枚举起点 然后O(1)查询子串hash值 然后O(n)找不一样的个数 复杂度是线性的 */ #include<iostr ...

  8. Notification封装(没做从网络下载)

    1.Notification作为消息通知,这里简单封装了使用 建立一个bean package com.jcut.view; /** * Author:JsonLu * DateTime:2016/2 ...

  9. Wpf TextChanged事件导致死循环,事件触发循环问题

    1.实例: 说明:当TextBox控件的Text内容发生变化时,TextChanged事件触发,并且会立即同步执行. 基于这个特点,设置一个全局变量标识,ChangeTxtB,如果是正在修改txtB的 ...

  10. Android LayoutInflater和findViewById 源码详解

    LayoutInflater大家很熟悉,简单点说就是布局文件XML解析器,setContentView函数也是调用了LayoutInflater 用法: View view = LayoutInfla ...