http://www.lydsy.com/JudgeOnline/problem.php?id=1011

题意:$f[i] = \sum_{j=1}^{i-1} \frac{M[i]M[j]}{i-j}$,求$1<=n<=10^5$的所有$f[i]$

orz 神题啊。。。

第一次做这种近似的题orz

首先n^2肯定是不可做的。。

然后看了题解。。

好神

首先得到$f[i]$表示第$i$个的能量, $g[i]$为题目给的$A*i$

$$f[i]=M_i \times \sum_{j=1}^{g[i]} \frac{M_j}{i-j}$$

而我们设$a=i+T$

$$f[a]=M_a \times \sum_{j=1}^{g[a]} \frac{M_j}{a-j}$$

$$ = M_a( \sum_{j=1}^{g[a-T]}\frac{M_j}{a-j}+\sum_{j=g[a-T]+1}^{g[a]} \frac{M_j}{a-j}) $$

$$ = M_a( \sum_{j=1}^{g[a-T]}\frac{M_j}{a-T-j} \times \frac{a-T-j}{a-j}+\sum_{j=g[a-T]+1}^{g[a]} \frac{M_j}{a-j}) $$

再利用数学上的技巧,可得到近似值:

$$ \approx M_a( \frac{f[a-T]}{M_{a-T}} \times \frac{a-T-\frac{g[a-T]}{2}}{a-\frac{g[a-T]}{2}}+\sum_{j=g[a-T]+1}^{g[a]} \frac{M_j}{a-j}) $$

右边数据小暴力搞就行了,t我一开始开1000wa了。。。。开100才a。。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mkpii make_pair<int, int>
#define pdi pair<double, int>
#define mkpdi make_pair<double, int>
#define pli pair<ll, int>
#define mkpli make_pair<ll, int>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const double eps=1e-8;
const int N=1e5+10, T=100;
int g[N], n;
double k, ans[N], m[N];
int main() {
read(n); scanf("%lf", &k);
for1(i, 1, n) scanf("%lf", &m[i]);
for1(i, 1, n) g[i]=(int)(floor(k*(double)i)+eps);
for1(i, 1, min(n, T)) {
for1(j, 1, g[i]) ans[i]+=m[j]/(i-j);
ans[i]*=m[i];
}
for1(i, min(n, T)+1, n) {
int pre=i-T;
for1(j, g[pre]+1, g[i]) ans[i]+=m[j]/(i-j);
ans[i]+=ans[pre]*(pre-g[pre]/2.0)/m[pre]/(i-g[pre]/2.0);
ans[i]*=m[i];
}
for1(i, 1, n) printf("%.6f\n", ans[i]+eps);
return 0;
}

  


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%,也算对

Source

 

【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]遥远的行星 (误差分析)

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

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

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

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

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

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

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

  6. [bzoj1011](HNOI2008)遥远的行星(近似运算)

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

  7. bzoj1011 [HNOI2008]遥远的行星

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

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

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

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

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

随机推荐

  1. Object.defineProperty 监听对象属性变化

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  2. javascript 作用域 通俗解释

    首先将作用域比喻为一座大楼: 第一层表示当前执行作用域.大楼顶层表示全局作用域. (1)js首先会在当前楼层进行查找变量,如果没有找到,就做电梯往上一层(二层)楼查找. (2)若还是没有找到继续往上查 ...

  3. 学习使用Jmeter做压力測试(一)--压力測试基本概念

    一.性能測试的概念         性能測试是通过自己主动化的測试工具模拟多种正常峰值及异常负载条件来对系统的各项性能指标进行測试.负载測试和压力測试都属于性能測试,两者能够结合进行. 通过负载測试, ...

  4. 【JS】jQuery中将数组转换成字符串join()和push()使用

    1.push()将元素依次添加至数组:2.join()将数组转换成字符串,里面可以带参数分隔符,默认[,] <script type = text/javascript> $(docume ...

  5. C-常用构造哈希函数

    1.定址法(比如0-100岁的人数统计, 可以按年龄作为散列地址, 1980年后每年出生人数的统计, 可以把"年限 - 1980"作为散列地址) 2.取余法 3.数字分析法(比如一 ...

  6. spring boot 在什么时候启动的tomcat

    我一直很好奇 spring boot 以哪种方式 启动的 tomcat  今天 特地跟踪了一下 大家都知道 spring 容器很核心的 方式 是org.springframework.context. ...

  7. C#:消息框

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  8. 剩下5种算法代码分析与使用示例(remove 、rotate 、sort、lower_bound、accumulate)

    一.移除性算法 (remove)  C++ Code  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ...

  9. atitit.故障排除--- 当前命令发生了严重错误。应放弃任何可能产生的结果sql server 2008

    atitit.故障排除--- 当前命令发生了严重错误.应放弃任何可能产生的结果sql server 2008 1. 现象 1 2. 原因:::sql server的bug 或者限制,查询的时候儿使用资 ...

  10. Composer fails to download http json files on "update", not a network issue, https fine

    "repositories": [ { "packagist": false }, { "type": "composer&quo ...