链接:传送门

题意:一个人自命不凡,他从1960年开始每10年更新一次计算机的最长储存长数。1960年为4位,每10年翻一倍。给出一个年份y,问这一年计算机可以执行的n!而不溢出的最大n值

思路:如果直接比较 2^x - 1 < n! 是一定会溢出的,所以不妨对左右取对数,使之变为 x*log10(2) < log10(n!) 。

使用斯特林公式优化一下n!的计算就能解决这个问题了。


/*************************************************************************
> File Name: poj2661.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年04月26日 星期三 22时52分03秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<cmath>
using namespace std; #define PI 3.1415926535
int y , n;
int main(){
double t = log10(2);
while(~scanf("%d",&y) && y){
int d = (y-1960)/10;
int x = pow(2.0,d)*4;
double tmp;
for(n = 1; 1 ; n++){
tmp = log10( sqrt(2*PI*n)) + n*log10(n*1.0/exp(1));
if(x*t<tmp) break;
}
printf("%d\n",n-1);
}
return 0;
}

POJ 2661Factstone Benchmark(斯特林公式)的更多相关文章

  1. poj 1423 打表/斯特林公式

    对于n位数的计算,我们可以采用(int)log10(n) + 1的方法得到n的位数 第一种方法: 对于n!位数的计算,log10(n!) = log10(1) + log10(2) + ... + l ...

  2. 【poj2661】Factstone Benchmark(斯特林公式)

    传送门 题意: 给出\(x,x\leq 12\),求最大的\(n\),满足\(n!\leq 2^{2^x}\). 思路: 通过斯特林公式: \[ n!\approx \sqrt{2\pi n}\cdo ...

  3. POJ 1423:Big Number 求N的阶乘的长度 斯特林公式

    Big Number Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27027   Accepted: 8626 Descr ...

  4. poj 2661 Factstone Benchmark (Stirling数)

    //题意是对于给定的x,求满足n! <= 2^(2^x)的最大的n//两边同取以二为底的对数,可得: lg2(n!) <= 2^x 1.   log2(n!) = log2(1) + lo ...

  5. poj 2661 Factstone Benchmark

    /** 大意: 求m!用2进制表示有多少位 m! = 2^n 两边同时取对数 log2(m!) = n 即 log2(1) + log2(2)+log2(3)+log2(4)...+log2(m) = ...

  6. poj 1502 最短路+坑爹题意

    链接:http://poj.org/problem?id=1502 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  7. POJ 1502 MPI Maelstrom(最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4017   Accepted: 2412 Des ...

  8. (poj)1502 MPI Maelstrom

    题目链接:http://poj.org/problem?id=1502 Description BIT has recently taken delivery of their processor A ...

  9. POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径)

    POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom ...

随机推荐

  1. Bash中文速查表

    最好用的中文速查表(Cheatsheet) 来源:https://github.com/skywind3000/awesome-cheatsheets 感谢网友们的贡献! ############## ...

  2. 指针FHQTreap

    不太友好的代码 题面依旧是普通平衡树 //Writer : Hsz %WJMZBMR%tourist%hzwer #include <bits/stdc++.h> #define LL l ...

  3. C# 日期格式

    # DateTime日期格式化 在C#中DateTime是一个包含日期.时间的类型,此类型通过ToString()转换为字符串时,可根据传入给Tostring()的参数转换为多种字符串格式. 目录 1 ...

  4. BA--无风机冷却塔

    无风机冷却塔的优点 1.无运转振动噪音传统冷却塔噪声源为冷却风扇马达运转所产生,其诱发之塔体振动,具有噪音共振加强性,为有效抑制振动之传导,须加装防震铁架及避震器.因冷却方式不同,LFC-N型无风机科 ...

  5. spring mvc流程理解

    1.controller处理的终究就是一个结果,默认是modelandview对象,controller里自己随便调用service或者dao,终究都还是在controller里有返回值. 2.  在 ...

  6. iOS动画之美丽的时钟

    1.终于效果图 2.实现思路 在ios中默认是绕着中心点旋转的,由于锚点默认在图层的中点,要想绕着下边中心点转,须要改变图层锚点的位置. 依据锚点.设置position坐标.为时钟的中点. 思考秒针旋 ...

  7. c# DataTable to Object Mapping

    public static class DataTableExtensions { public static IList<T> ToList<T>(this DataTabl ...

  8. cocos2d-x之浅析Hello World

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  9. UVA - 11722 Joining with Friend 几何概率

                            Joining with Friend You are going from Dhaka to Chittagong by train and you ...

  10. 0x05 排序

    说是排序结果就是各种奇技淫巧 中位数被坑多了久病成医,例题一题搞笑一题糖果传递(昨晚精神那么好效率还那么差) #include<cstdio> #include<iostream&g ...