题目大意

  给你\(n,b\),还有一个数列\(a\)。

  对于每个\(i\)求\(f_i=\sum_{j=1}^{bi}\frac{a_ja_i}{i-j}\)。

  绝对误差不超过\(5\%\)就算对。

  \(0.01\leq b\leq 0.05,n\leq {10}^5\)  

题解

  我好像在以前的UR做过一道用误差来搞事情的题:【UER#7】天路

  这题网上很多代码算出来的答案误差太大了。比如说\(n={10}^5,b=0.35,a_1=a_n={10}^7,\)其他的是\(0\)。这些代码会给出\(f_n=1212121212.121212\),但实际上\(f_n=1000010000.1\)。

  这道题的正确做法也是对于每一个\(i\)把\(j\)分段,只不过不是分成\(1\)段,而是分成好几段。对于同一段内的\(j\)满足\(\frac{1}{i-j_1}<1.05\times\frac{1}{1-j_2}\),这样取\(j_1\)代替组内的\(j\)来计算误差就不会超过\(5\%\)了。(其实也可以让组内误差\(<\frac{1.05}{0.95}\))。

  时间复杂度:\(O(n)\)。

代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<cmath>
#include<functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void sort(int &a,int &b)
{
if(a>b)
swap(a,b);
}
void open(const char *s)
{
#ifndef ONLINE_JUDGE
char str[100];
sprintf(str,"%s.in",s);
freopen(str,"r",stdin);
sprintf(str,"%s.out",s);
freopen(str,"w",stdout);
#endif
}
int rd()
{
int s=0,c;
while((c=getchar())<'0'||c>'9');
do
{
s=s*10+c-'0';
}
while((c=getchar())>='0'&&c<='9');
return s;
}
int upmin(int &a,int b)
{
if(b<a)
{
a=b;
return 1;
}
return 0;
}
int upmax(int &a,int b)
{
if(b>a)
{
a=b;
return 1;
}
return 0;
}
int b[100010];
double c[100010];
double a[100010];
double s[100010];
int main()
{
open("bzoj1011");
int n;
double x;
scanf("%d%lf",&n,&x);
int i,j;
int m=floor(x*n);
int t=0;
for(i=0;i<=m;i++)
c[i]=double(n)/(n-i);
for(i=1;i<=m;i++)
if(i==m||c[i]>c[b[t]]*1.04)
b[++t]=i;
for(i=1;i<=n;i++)
{
scanf("%lf",&a[i]);
s[i]=s[i-1]+a[i];
int last=0;
double ans=0;
for(j=1;j<=t;j++)
{
int now=floor(double(b[j])/n*i);
now=min(now,i-1);
ans+=a[i]*(s[now]-s[last])/(i-last-1);
last=now;
}
printf("%.10lf\n",ans);
}
return 0;
}

【BZOJ1011】【HNOI2008】遥远的行星 误差分析的更多相关文章

  1. BZOJ 1011 [HNOI2008]遥远的行星 (误差分析)

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 4974  Solved ...

  2. bzoj1011 [HNOI2008]遥远的行星

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 2480  Solved ...

  3. BZOJ1011 [HNOI2008]遥远的行星 【奇技淫巧】

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special Judge Submit: 5058  Solve ...

  4. BZOJ1011:[HNOI2008]遥远的行星(乱搞)

    Description 直线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=Mi*Mj/(j-i) 其中A为很小的常量, ...

  5. [bzoj1011](HNOI2008)遥远的行星(近似运算)

    Description 直 线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=Mi*Mj/(j-i) 其中A为很小的常量, ...

  6. 【bzoj1011】[HNOI2008]遥远的行星

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 3711  Solved ...

  7. BZOJ 1011 [HNOI2008]遥远的行星

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 2559  Solved ...

  8. 1011: [HNOI2008]遥远的行星

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 2241  Solved ...

  9. [HNOI2008]遥远的行星

    题目描述 直线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=Mi*Mj/(j-i) 其中A为很小的常量,故直观上说每颗行 ...

  10. 【BZOJ】1011: [HNOI2008]遥远的行星(近似)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1011 题意:$f[i] = \sum_{j=1}^{i-1} \frac{M[i]M[j]}{i-j ...

随机推荐

  1. JQuery 的Ajax的使用

    JSON:一种轻量级的数据表示方法,优点:传输方便,占用字节少 XML:一种偏重量级的数据表示方法,优点:格式清晰,占用字节多,大量的字节都浪费在了标签上: 网络传输我们常使用json,因为浏览器解析 ...

  2. Python_动态参数、名称空间、作用域、作用域链、加载顺序、函数的嵌套、global、nonlocal

    1.动态参数 当实参数量与形参数量相等时,参数传递正常. def func1(a, b, c): pass func1(1, 2, 3) 当实参数量与形参数量不相等时,则会报错. def func1( ...

  3. composer 自动加载类 通过psr

    项目地址  git@github.com:brady-wang/composer.git "autoload":{ "classmap":[ "Lib ...

  4. vue页面传参和接参

    https://blog.csdn.net/zhouzuoluo/article/details/81259298(copy) js** this.$router.push({ name: 'Flow ...

  5. JavaScript charAt() 方法

    <script> var str="abcdef"; alert(str[0]); //a,高版本浏览器兼容 alert(str.charAt(0)); //a,兼容所 ...

  6. 字符串正则替换replace第二个参数是函数

    zepto中 //将字符串转成驼峰式的格式 camelize = function (str) { return str.replace(/-+(.)?/g, function (match, chr ...

  7. windows10企业版2016长期服务版激活

    win10 2016 长期服务版的ISO文件中本身就带有KMS激活KEY,不用输入任何KEY,连接网络进入CMD,只要输入:slmgr /skms kms.digiboy.irslmgr /ato这两 ...

  8. win10远程桌面连接提示身份验证错误,要求的函数不受支持的解决方案

    转自https://www.baidu.com/link?url=67JXh4h79mN47mEenuH_ElGkSh9_GdOiY-Xp9Ihw0_mQIZHrPx-HxY3EIm_nTZKPoRZ ...

  9. linux audit (9)--生成audit报表

    aureport这个命令可以生成一个总结性的柱状图报表,默认情况下,在/var/log/audit目录下的所有日志文件都会生成一个报表,也可以使用如下命令来指定一个不同的文件,aureport opt ...

  10. 自定义组件Component

    定义compa组件 由4个页面构成 compa.js: compa.json: compa.wxml: compa:wxss: 1.compa.json:在json文件进行自定义组件声明 { &quo ...