链接:传送门

题意:一个人自命不凡,他从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. PHP 7.1.15安装zabbix-3.2.6出现问题解决

    出现问题,显示 A non well formed numeric value encountered [zabbix.php:21 → require_once() → ZBase->run( ...

  2. Python CSV- 绘制气温图表

    CSV-  绘制气温图表 资源: 链接: https://pan.baidu.com/s/1kqREk-sRnOcC34Mh1lBDHQ 提取码: uyx7 # highs_lows_Jul.py 最 ...

  3. mybatis入门截图总结

    原生态jdbc存在的问题 ------------------- ----------------------- ------- 环境的搭建 ----------------------------- ...

  4. (OpenExplorer For Eclipse)Eclipse 中打开工程目录的插件(转)

    我们想在Eclipse中的打开工程目录,Eclipse 自身没有这个功能,我们可以安装一个插件来实现这个功能.具体的操作方法如下: (1).到以下链接中下载插件:https://github.com/ ...

  5. muduo库源码剖析(二) 服务端

    一. TcpServer类: 管理所有的TCP客户连接,TcpServer供用户直接使用,生命期由用户直接控制.用户只需设置好相应的回调函数(如消息处理messageCallback)然后TcpSer ...

  6. 定时任务为什么不用Timer

    在做定时任务的时候,有的同学可能能会用到Timer这个定时任务的辅助类, 可是使用它会有潜在的风险,风险例如以下, (1)时间计算不准确问题     由于Timer是以绝对时间计算定时任务的,会受到系 ...

  7. sedna载入xml文件

    如果有一个xml文件a.xml.须要把它载入到sedna数据库xml_db里. sedna是通过se_term把xml载入到数据库的.有两种方法: 1.通过se_term的-query參数. se_t ...

  8. 【前端福利】用grunt搭建自己主动化的web前端开发环境-完整教程

    jQuery在使用grunt,bootstrap在使用grunt,百度UEditor在使用grunt,你没有理由不学.不用! 1. 前言 各位web前端开发者.假设你如今还不知道grunt或者听说过. ...

  9. USACO holstein 超时代码

    /* ID:kevin_s1 PROG:holstein LANG:C++ */第八组数据跪了.半天都不出结果 #include <iostream> #include <cstdi ...

  10. jsp不通过form和Ajax提交

    在页面里面我们一般都通过form表单和Ajax向后台提交请求,但是我如今页面没有form表单,也不想通过ajax异步提交. 解决方式例如以下:location.href="${rootPat ...