题目大意

  给你\(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. UnderWater+SDN论文之五

    Underwater Sensor Networks with Mobile Agents: Experience from the Field Source: LNICST 2013 论文是来自两个 ...

  2. Java工具类——UUIDUtils

    借用一下百度百科的解释,来看一下UUID是什么. UUID含义是通用唯一识别码 (Universally Unique Identifier),这 是一个软件建构的标准,也是被开源软件基金会 (Ope ...

  3. 【学习总结】C-翁恺老师-入门-第3周<循环>

    [学习总结]C-翁恺老师-入门-总 1-求一个整数的位数:引入循环while 注:循环体内要有改变循环的机会,要不然就死循环了啊! 注:手写推测程序是否正确. 注:测试程序-边界:个位数.10.0.负 ...

  4. chrome extensions notifications

    developer.chrome.comhttps://developer.chrome.com/extensions/notifications notification | MDNhttps:// ...

  5. java的static与C#的static的异同

    static static同样可以用在类.方法.变量上面,但是在java和C#中所表示的意思完全不同,我个人的总结是C#中的静态和非静态是有一个明显的分界的,静态的是属于类级别的,而非静态的是属于实例 ...

  6. java 浅拷贝和深拷贝 对象克隆clone

    分一下几点讨论: 为什么要克隆? 如何实现克隆 浅克隆和深克隆 解决多层克隆问题 总结 一:为什么要克隆? 大家先思考一个问题,为什么需要克隆对象?直接new一个对象不行吗? 答案是:克隆的对象可能包 ...

  7. [转帖]SAP一句话入门:Material Management

    SAP一句话入门:Material Management http://blog.vsharing.com/MilesForce/A616683.html 让我们来关注供应链上的另一个模块Materi ...

  8. taro实战1

    npm install -g @tarojs/cli //或 yarn global add @tarojs/cli

  9. Hbase 架构体系

    有2个节点进程,一个是master,另一是regionserver.

  10. 1、通过eureka创建注册中心

    第一个demo(用户需要调用电影服务) 1.创建项目 new starter project 勾选上Eureka Server 2.编写application.yml #配置端口 server: po ...