正题
构造一个函数:,可以打表发现当
时,
其实很小很小。
所以我们可以直接用一次牛顿迭代来求出的
。
具体的来说
那么.
可以证明误差不大。
#include<bits/stdc++.h>
using namespace std;
namespace Mker
{
// Powered By Kawashiro_Nitori
// Made In Gensokyo, Nihon
#define uint unsigned int
uint sd;int op;
inline void init() {scanf("%u %d", &sd, &op);}
inline uint uint_rand()
{
sd ^= sd << 13;
sd ^= sd >> 7;
sd ^= sd << 11;
return sd;
}
inline double get_n()
{
double x = (double) (uint_rand() % 100000) / 100000;
return x + 4;
}
inline double get_k()
{
double x = (double) (uint_rand() % 100000) / 100000;
return (x + 1) * 5;
}
inline void read(double &n,double &a, double &b)
{
n = get_n(); a = get_k();
if (op) b = a;
else b = get_k();
}
}
int T;
double n,a,b;
int main(){
scanf("%d",&T);
Mker::init();
double ans=0.000000;
while(T--){
Mker::read(n,a,b);
ans+=1.0/(a*pow(n,a-1)+b*pow(n,b-1));
}
printf("%.8lf\n",ans);
}
本文介绍了一种利用牛顿迭代法高效求解特定形式函数的方法。通过构造函数和使用一次牛顿迭代,可以精确求得在给定条件下的函数值。文章提供了完整的C++代码实现,包括随机数生成、参数读取和迭代过程。
949

被折叠的 条评论
为什么被折叠?



