【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}$,求$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
3
5
6
2
4
Sample Output
0.000000
0.000000
1.968750
2.976000
HINT
精确结果应该为0 0 0 2 3,但样例输出的结果误差不超过5%,也算对
Source
【BZOJ】1011: [HNOI2008]遥远的行星(近似)的更多相关文章
- BZOJ 1011 [HNOI2008]遥远的行星
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 2559 Solved ...
- BZOJ 1011 [HNOI2008]遥远的行星 (误差分析)
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 4974 Solved ...
- [BZOJ 1011] [HNOI2008] 遥远的行星 【近似解】
题目链接: BZOJ - 1011 题目分析 这道题的特别之处在于,答案可以有5%的误差. 嗯..So? 我还是不会,于是看题解. 神犇的题解就是利用这误差范围求一个近似解. 怎么求近似解呢?假如 g ...
- BZOJ.1011.[HNOI2008]遥远的行星(思路 枚举)
题目链接 设当前为\(i\),令\(j=\lfloor a*i\rfloor\),\(1\sim j\) 即为对\(i\)有贡献的行星,这一区间的答案应为\[f[i]=M_i*\sum_{k=1}^j ...
- 1011: [HNOI2008]遥远的行星
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 2241 Solved ...
- [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: 2480 Solved ...
- 【bzoj1011】[HNOI2008]遥远的行星
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 3711 Solved ...
- BZOJ1011 [HNOI2008]遥远的行星 【奇技淫巧】
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special Judge Submit: 5058 Solve ...
随机推荐
- codechef The Ball And Cups题解
The Ball And Cups At the end of a busy day, The Chef and his assistants play a game together. The ga ...
- Xcode5 打包 发布配置
http://www.cnblogs.com/zhaoqingqing/p/3553750.html 主题 Unity导出Xcode项目,使用Xocde打包ipa并提交到AppStore 步骤 1.设 ...
- sql存储过程等-版本控制
数据库开发人员总在想,每次修改了函数/存储过程,我们都得自己做备份,用以历史参考,当发现错误的时候,可以回滚 SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON ...
- 错误代码: 1066 Not unique table/alias: 'c'
1.错误描写叙述 1 queries executed, 0 success, 1 errors, 0 warnings 查询:SELECT (SELECT CONCAT( s.name, '/', ...
- 如何判断自己家的宽带是否有公网IP
1)点击链接 http://www.net.cn/static/customercare/yourIP.asp 抓取自己的IP地址 2)打开一个命令提示符窗口 tracert <刚才获取的IP& ...
- nginx配置用户认证
location ~ .*admin\.php$ { auth_basic "weifenglinux auth"; auth_ba ...
- 中文latex去掉图片描述
中文latex去掉图片描述,或者自定义: \usepackage{caption} \caption*{the title of figure}就可以自己定义了.
- Python线程指南(转)
1. 线程基础 1.1. 线程状态 线程有5种状态,状态转换的过程如下图所示: 1.2. 线程同步(锁) 多线程的优势在于可以同时运行多个任务(至少感觉起来是这样).但是当线程需要共享数据时,可能存在 ...
- EMQTT benchmark测试
#-c 最大的客户端数据, -i:时间间隔 -t:订阅主题 -q:订阅方式 ./emqtt_bench_sub -c 50000 -i 10 -t bench/%i -q 2 notice: You ...
- Python 实现小数和百分数的相互转换
# -*- coding: utf-8 -*- #百分比转换位小数 # -*- coding: utf-8 -*- s = '20%' # 默认要转换的百分比是字符串aa = float(s.stri ...