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. UI5-文档-4.22-Expression Binding

    有时预定义的SAPUI5类型不够灵活,您希望在视图中执行简单的计算或格式化——这正是表达式真正有用的地方.我们使用它们根据数据模型中的当前数字格式化价格. Preview The price is n ...

  2. Cookie的过期时间设置

    https://pan.baidu.com/s/1ibUQhLt6ZgVyhVM6mnrtHg 密码:9psc

  3. whlie and for

    public class TestWhileAndFor { /**测试 while和for循环练习 * 100 以内的奇数和偶数的和 * @author Administrator * */ pub ...

  4. Mysql通过SQL脚本复制表

    create table if not exists t_dest like t_src 其中,t_src是要复制的原始表,t_dest是要创建的新表.

  5. Jmeter分布式

    Jmeter运行时十分耗CPU和内存,在实际应用中有时一台机器不能满足测试要求,这时就需要利用多台机器来进行分布式.   Jmeter分布式的测试框架:框架中所有的测试脚本都要从测试主机传送到测试从机 ...

  6. RegExp.$1 简单理解

    RegExp 是javascript中的一个内置对象.为正则表达式.RegExp.$1是RegExp的一个属性,指的是与正则表达式匹配的第一个 子匹配(以括号为标志)字符串, 以此类推,RegExp. ...

  7. goim源码分析与二次开发-comet分析一

    因为要完成一个聊天的项目,所以借鉴了goim,第一篇分析打算半原版,先摘抄http://www.jianshu.com/p/8bd96a9a473d他的一些理解,写这些还是为了让自己更好的理解这个项目 ...

  8. 57. Insert Interval (Array; Sort)

    Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...

  9. 【校招面试 之 剑指offer】第9-2题 用两个队列实现一个栈

    #include<iostream> #include<queue> using namespace std; // 对于出栈解决的思路是:将queue1的元素除了最后一个外全 ...

  10. 对象之int介绍

    #Auther Bob #--*--conding:utf-8 --*-- #创建两个int的对象,age1和age2 age1 = 10 age2 = int(1) #查看对象的类 print(ty ...