POJ 2661Factstone Benchmark(斯特林公式)
链接:传送门
题意:一个人自命不凡,他从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(斯特林公式)的更多相关文章
- poj 1423 打表/斯特林公式
对于n位数的计算,我们可以采用(int)log10(n) + 1的方法得到n的位数 第一种方法: 对于n!位数的计算,log10(n!) = log10(1) + log10(2) + ... + l ...
- 【poj2661】Factstone Benchmark(斯特林公式)
传送门 题意: 给出\(x,x\leq 12\),求最大的\(n\),满足\(n!\leq 2^{2^x}\). 思路: 通过斯特林公式: \[ n!\approx \sqrt{2\pi n}\cdo ...
- POJ 1423:Big Number 求N的阶乘的长度 斯特林公式
Big Number Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27027 Accepted: 8626 Descr ...
- poj 2661 Factstone Benchmark (Stirling数)
//题意是对于给定的x,求满足n! <= 2^(2^x)的最大的n//两边同取以二为底的对数,可得: lg2(n!) <= 2^x 1. log2(n!) = log2(1) + lo ...
- poj 2661 Factstone Benchmark
/** 大意: 求m!用2进制表示有多少位 m! = 2^n 两边同时取对数 log2(m!) = n 即 log2(1) + log2(2)+log2(3)+log2(4)...+log2(m) = ...
- poj 1502 最短路+坑爹题意
链接:http://poj.org/problem?id=1502 MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- POJ 1502 MPI Maelstrom(最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4017 Accepted: 2412 Des ...
- (poj)1502 MPI Maelstrom
题目链接:http://poj.org/problem?id=1502 Description BIT has recently taken delivery of their processor A ...
- 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 ...
随机推荐
- 使用kubeadm在CentOS上搭建Kubernetes1.14.3集群
练习环境说明:参考1 参考2 主机名称 IP地址 部署软件 备注 M-kube12 192.168.10.12 master+etcd+docker+keepalived+haproxy master ...
- CSS 居中【整合】
<center> text-align:center 在父容器里水平居中 inline 文字,或 inline 元素 vertical-align:middle 垂直居中 inline 文 ...
- 小程序中 wx.navigateTo 页面跳转没有反应?
页面js文件中加入 show: function () {wx.navigateTo({url: ‘/pages/show/show’})} 这个函数 目的在于要做跳转到新的页面,但是你可能会遇到一个 ...
- selenium+java实现浏览器前进、后退和刷新
- 接口(interface) 可以 new()吗???~
比如 一个接口 A ,里面有一个方法fun1(),一般我们是先定义它的实现再引用它,比如 public class ImpA implements A{ public void fun1(){ //d ...
- Struts2校验
struts2校验有两种实现方法: 手工编写代码实现(基本验证) //login.jsp <font color="red"><s:fielderror/> ...
- C语言:一个涉及指针函数返回值与printf乱码、内存堆栈的经典案例
一个奇怪的C语言问题,涉及到指针.数组.堆栈.以及printf.以下实现: 整数向字符串的转换,返回字符串指针,并在main函数中调用printf显示. #include<stdio.h> ...
- Qt on Android:资源文件系统qrc与assets
使用 Qt 为 Android 开发应用时,有时我们的应用会携带一些资源文件,如 png . jpg 等,也可能有一些配置文件,如 xml 等.这些文件放在哪里呢? 有两种方式: qrc assets ...
- UVALive 6663 Count the Regions 离散+bfs染色_(:зゝ∠)_
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=4675">点击打开链接 gg.. ...
- js保留两位小数的解决的方法
var a = 123.456; a = a..toFixed(2); alert(a);//结果:123.46