POJ 1423 Big Number

题意:求n阶乘的位数。

解法:斯特林公式,,然后取log10就是位数了,因为精度问题需要化简这个式子,特判1。

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
const double pi = acos(-1.0);
const double e = 2.718281828459;
int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        int n;
        scanf("%d", &n);
        if(n == 1)
        {
            puts("1");
            continue;
        }
        printf("%d\n", (int)ceil(0.5 * log10(2.0 * pi * n) + log10((double)n) * n - log10(e) * n));
    }
    return 0;
}

  

时间: 2024-08-04 04:50:06

POJ 1423 Big Number的相关文章

poj 2104 K-th Number(划分树模板)

划分树模板题,敲上模板就ok了. #include<algorithm> #include<iostream> #include<cstring> #include<vector> #include<cstdio> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> #define MP

【POJ 1019】 Number Sequence

[POJ 1019] Number Sequence 二分水题 放组合数学里...可能有什么正规姿势吧Orz 112123123412345...这种串 分成长度1 2 3 4 5...的串 注意有多位数 把长度累加到一个数组里 注意要累加 因为查询的时候查的是原串中对应位置的数 因此要累加上前一次的长度 然后二分处该串前的总长 用查询的位置-之前串的总长 就是在最长的串中的位置 因此还要打个最长串的表 这些我都写一个循环里了 看着有点乱 可以拆开写... 代码如下: #include <ios

POJ 2329 -- Nearest number - 2

Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4224   Accepted: 1308 Description Input is the matrix A of N by N non-negative integers. A distance between two elements Aij and Apq is defined as |i ? p| + |j ? q|. Your program must repla

[划分树] POJ 2104 K-th Number

K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 51732   Accepted: 17722 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse

POJ 2014.K-th Number 区间第k大 (归并树)

K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 57543   Accepted: 19893 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse

POJ 2104 K-th Number(分块+二分)

题目链接:http://poj.org/problem?id=2104 题目: Description You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return qu

POJ 2104 K-th Number (划分树)

                                                            K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 52651   Accepted: 18091 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures

【POJ 1351】Number of Locks

Number of Locks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1198   Accepted: 589 Description In certain factory a kind of spring locks is manufactured. There are n slots (1 < n < 17, n is a natural number.) for each lock. The height

poj 2104 K-th Number(划分树)

题目链接:http://poj.org/problem?id=2104 题目分析:该问题给定一段区间中的值,再给定一段查询区间[ql, qr],需要给出该查询区间中的值在排序后的第K大的值: 使用划分树即可解决该问题:划分树的建树的复杂度为O(NlogN),查询一个区间的第K大值的复杂度为O(logN): 代码如下: #include <cstdio> #include <iostream> #include <algorithm> using namespace st