【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 ...
随机推荐
- (第十三周)Final阶段用户调查报告
项目名:食物链教学工具 组名:奋斗吧兄弟 组长:黄兴 组员:李俞寰.杜桥.栾骄阳.王东涵 用户调查报告 调查时间:2016年12月1日 21:00——2016年12月3日 12:00 项目分享链接 ...
- Day2 Numerical simulation of optical wave propagation之标量衍射理论基本原理(二)
2.麦克斯韦方程组的简单行波解 讨论通过线性.各向同性.均匀.无色散.无限电荷和电流的电介质材料的光波传输.在这种情况下,介质具有如下属性: (1)推导获得波动方程( 由麦克斯韦方程组导出的.描述电磁 ...
- PS调出冷绿色电影画面风格
原图 一.按照惯例先磨皮,我修照片的习惯是,先拉一层色阶,使直方图平均分配,画面会显得没那么灰,当然,这只是个人喜好,先加后加都没所谓. 二.由于脸部的亮度不够,显得有点脏.所以这一步主要是通过拉曲线 ...
- UITableView加载数据,没有数据,没有网络界面处理
https://blog.csdn.net/chmod_r_755/article/details/53231461 俗话说的好,傻逼的APP都是相似的,牛逼的APP各有各的牛逼...但是UITabl ...
- 多线程系列之八:Thread-Per-Message模式
一,Thread-Per-Message模式 翻译过来就是 每个消息一个线程.message可以理解为命令,请求.为每一个请求新分配一个线程,由这个线程来执行处理.Thread-Per-Message ...
- Java 学习使用常见的开源连接池
目录 连接池介绍 自定义连接池 JDBC Tomcat Pool DBCP(DataBase Connection Pool) 使用配置文件来设置DBCP C3P0 Druid 连接池介绍 在说连接池 ...
- Golang的类型断言
类型断言即判断一个变量是不是某个类型的实例,这个经常用在判断接口的类型,基本的格式: y, ok := x.(type) 上面的语句用于判断变量x是不是type类型,有两种结果: x是type类型的变 ...
- marMariaDB & MYSQL flexviews
Using Flexviews - part one, introduction to materialized views - Percona Database Performance Bloght ...
- 二、npm scripts
一.执行原理 安装npm 包,会将其package.json bin 字段添加到node_modules bin 里面,创建对应的.cmd文件,因此: 例如: "scripts": ...
- IdentityServer4【QuickStart】之设置和概述
设置和概述 有两个基本的方式来开启一个新的IdentityServer项目: 从头开始 从asp.net Identity模板开始 如果你从头开始,我们提供了一些基于内存中构建的存储,所以你不必一开始 ...