1011: [HNOI2008]遥远的行星

Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special Judge
Submit: 4974  Solved: 1864
[Submit][Status][Discuss]

Description

  直线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=
Mi*Mj/(j-i) 其中A为很小的常量,故直观上说每颗行星都只受到距离遥远的行星的作用。请计算每颗行星的受力
,只要结果的相对误差不超过5%即可.

Input

  第一行两个整数N和A. 1<=N<=10^5.0.01< a < =0.35,接下来N行输入N个行星的质量Mi,保证0<=Mi<=10^7

Output

  N行,依次输出各行星的受力情况

Sample Input

5 0.3
3
5
6
2
4

Sample Output

0.000000
0.000000
0.000000
1.968750
2.976000

HINT

  精确结果应该为0 0 0 2 3,但样例输出的结果误差不超过5%,也算对

 
析:因为这个题误差不超过 5%,所以对于小数据我们就可以直接进行暴力,然后大数据我们就可以进行误差分析,A * j 得到一个数 t,我们就可以用 j - t / 2来代替所有的分母,这样的话就可以用前缀进行优化了,时间复杂度就小了,但是要注意这个题的是卡精度的,在求 t 的时候要加上一个eps,来控制精度。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int maxn = 1e5 + 10;
const int maxm = 3e5 + 10;
const int mod = 100003;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, -1, 0, 1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} double sum[maxn];
double b[maxn]; int main(){
double a;
scanf("%d %lf", &n, &a);
for(int i = 1; i <= n; ++i){
scanf("%lf", b + i);
sum[i] = sum[i-1] + b[i];
double ans = 0.;
int t = i * a + eps;
if(i > 100){
double xx = i - i * a / 2.;
ans = sum[t] * 1. * b[i] / xx;
}
else {
for(int j = 1; j <= t; ++j)
ans += b[i] * 1. * b[j] / (i - j);
}
printf("%.6f\n", ans);
}
return 0;
}

  

BZOJ 1011 [HNOI2008]遥远的行星 (误差分析)的更多相关文章

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

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

  2. [BZOJ 1011] [HNOI2008] 遥远的行星 【近似解】

    题目链接: BZOJ - 1011 题目分析 这道题的特别之处在于,答案可以有5%的误差. 嗯..So? 我还是不会,于是看题解. 神犇的题解就是利用这误差范围求一个近似解. 怎么求近似解呢?假如 g ...

  3. BZOJ.1011.[HNOI2008]遥远的行星(思路 枚举)

    题目链接 设当前为\(i\),令\(j=\lfloor a*i\rfloor\),\(1\sim j\) 即为对\(i\)有贡献的行星,这一区间的答案应为\[f[i]=M_i*\sum_{k=1}^j ...

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

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

  5. 【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 ...

  6. bzoj1011 [HNOI2008]遥远的行星

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

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

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

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

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

  9. [HNOI2008]遥远的行星

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

随机推荐

  1. PuTTY免输密码自动登录Linux

    1.使用PuTTY安装目录里的puttygen.exe工具.先点“生成(Generate)”,然后随意移动鼠标直到进度条填满,即可生成密钥 公钥部分:把上边那一段文字全选->复制备用.(不要点击 ...

  2. 前端-CSS-6-盒子模型

    上面的布局宽度div{ width: 200px; height: 200px; border: 10px solid red; padding: 20px; } ------------------ ...

  3. vue基础——计算属性和侦听器

    计算属性——介绍 模板内的表达式非常便利,但是设计他们的初衷是用于简单计算的.在模板中放入太多的逻辑会让模板太过沉重切难以维护.如下: <div id="example"&g ...

  4. 从底层谈WebGIS 原理设计与实现(一):开篇

    从底层谈WebGIS 原理设计与实现(一):开篇 作者:naaoveGI…    文章来源:http://www.cnblogs.com/naaoveGIS/    点击数:4773    更新时间: ...

  5. jquery实现背景图片动态适应

    背景 在我的一个项目中用到了背景图片,发现其中有一个问题,当页面长度动态变化时,原来能占满全部内容背景的图片会变得不能占满全部背景.如下图的效果: 这是正常的,背景图片占满全屏 当页面内容变长出现了滚 ...

  6. JAVA NIO学习记录1-buffer和channel

    什么是NIO? Java NIO(New IO)是从Java 1.4版本开始引入的一个新的IO API,可以替代标准的Java IO API.NIO与原来的IO有同样的作用和目的,但是使用的方式完全不 ...

  7. delphi实现映射和断开网络驱动器

    type TNetDiskMapper=class private FNetResource: TNetResource; FUserName,FPassWord:PWideChar; public ...

  8. IDEA artifacts Web Application:Exploded Web Application:Archive

    首先,artifacts是maven中的一个概念,表示项目/modules如何打包,比如jar,war,war exploded,ear等打包形式,一个项目或者说module有了artifacts 就 ...

  9. for循环计算阶乘

    int x = 10; for(int y = x - 1; y >= 1; y--) { x = x * y; } System.out.println(x); 从10乘到1的阶乘写法. lo ...

  10. LibreOJ 6282 数列分块入门 6(在线插入在线查询)

    题解:还是分块,将每个块存入vector,然后在插入的时候就是sqrt(n)级的重构,如果块太大了,暴力将这个块拆开. 代码如下: #include<cmath> #include< ...