【BZOJ1011】【HNOI2008】遥远的行星 误差分析
题目大意
给你\(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】遥远的行星 误差分析的更多相关文章
- BZOJ 1011 [HNOI2008]遥远的行星 (误差分析)
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 4974 Solved ...
- bzoj1011 [HNOI2008]遥远的行星
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 2480 Solved ...
- BZOJ1011 [HNOI2008]遥远的行星 【奇技淫巧】
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special Judge Submit: 5058 Solve ...
- BZOJ1011:[HNOI2008]遥远的行星(乱搞)
Description 直线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=Mi*Mj/(j-i) 其中A为很小的常量, ...
- [bzoj1011](HNOI2008)遥远的行星(近似运算)
Description 直 线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=Mi*Mj/(j-i) 其中A为很小的常量, ...
- 【bzoj1011】[HNOI2008]遥远的行星
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 3711 Solved ...
- BZOJ 1011 [HNOI2008]遥远的行星
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 2559 Solved ...
- 1011: [HNOI2008]遥远的行星
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 2241 Solved ...
- [HNOI2008]遥远的行星
题目描述 直线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=Mi*Mj/(j-i) 其中A为很小的常量,故直观上说每颗行 ...
- 【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 ...
随机推荐
- 使用模块PIL 生成 随机验证码
--------------默认自己无能,无疑是给失败制造机会!你认为自己是什么样的人,就将成为什么样的人. 要使用PIL模块. 安装: 1 pip3 install pillow 基本使用 1. 创 ...
- VMware vSphere 6 序列号
vSphere 6 Hypervisor HY0XH-D508H-081U8-JA2GH-CCUM2 4C4WK-8KH8L-H85J0-UHCNK-8CKQ8 NV09R-2W007-08D38-C ...
- Python-面向对象简介
面向对象介绍 学习面向对象过程中会遇到一些名词,我们先解释下 名词解释 类:一个类即是对一类拥有相同属性的对象的抽象.蓝图.原型.模板.在类中定义了这些对象的都具备的属性(variables(data ...
- iOS蓝牙开发之iBeacon技术
iBeacon组成信息: 1 .UUID(universally unique identifier):一个128位的唯一标识一个或多个Beacon基站为特定类型或特定的组织. 2. Major:一个 ...
- p33自然同态
如何理解两个划线的地方 1.因为,所以所以ker(π|_H)=kerπ∩H=N∩H 2.gN=Ng,对任意的g 属于G 因为 N被H/N 包含 也对任意的 g 属于 HN成立 ...
- ES使用C#添加和更新文档
ElasticSearch 使用C#添加和更新文档 这是ElasticSearch 2.4 版本系列的第四篇: 第一篇:ES1:Windows下安装ElasticSearch 第二篇:ES2:Elas ...
- Django之Django终端打印SQL语句
Django之Django终端打印SQL语句 在Django项目中,settings.py文件中,在最后添加如下代码即可实现在Django终端打印SQL语句. LOGGING = { 'version ...
- Ubuntu18.04更新源
一.备份/etc/apt/sources.list文件 cd /etc/apt sudo cp sources.list sources.list.old 二.选择国内常用的源 #阿里源 deb ht ...
- [官网]Red Hat Enterprise Linux Release Dates
Red Hat Enterprise Linux Release Dates https://access.redhat.com/articles/3078 The tables below list ...
- CLOUD添加自定义基础数据
1.打开bos平台,文件-新建-复制-基础资料 2.新建目标对象 3.发布 4.开始新增对象 5.明细维护,完成 6.添加成功