2048: [2009国家集训队]书堆
Time Limit: 10 Sec Memory Limit: 259 MB
Description
Input
第一行正整数 N M
Output
一行(有换行符),L,表示水平延伸最远的整数距离 (不大于答案的最大整数)
Sample Input
样例
Input: 1 100
Output: 49
Input: 2 100
Output: 74
数据保证答案 < 10^6
题目较水,不想找图弄详解了,popoqqq题解
其实大家自己算算就发现了,主要是知不知道这个调和级数极限公式。
1/1+1/2+1/3+…+1/n = ln(n+1)+r。
其中r为欧拉常数 近似值约为0.57721566490153286060651209
但这是极限公式 对于n比较小的情况误差会比较大 所以当n比较小的时候O(n)暴力出解 n比较大的时候套用公式。
这个精度很迷呀,表示并不知道怎么算,搞搞试试呗【弱基的方法。
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define eps 1e-5
#define r 0.5772156649
using namespace std;
LL n, m;
double ans;
int main(){
cin >> n >> m;
if(n <= 10000)
for(int i=1; i<=n; i++)
ans += 0.5 / i;
else
ans = log( n + 1.0 ) + r, ans /= 2.0;
ans *= m;
printf("%d\n", (int)(ans-eps) );
return 0;
}