1011: [HNOI2008] Distant planet time limit:10 Sec Memory limit:162 mbsec Special Judge
submit:2559 solved:923
[Submit] [Status] [Discuss] Description
On a straight line of n planets, there are planets I in the X=i, and Planet J is subjected to the force of the planet I, when and only as I<=aj. At this time J is subjected to a force of fi->j=mi*mj/(J-i) where a is a very small constant, so it is intuitively said that each planet is only affected by distant planets. Please calculate the force of each planet, as long as the relative error of the result is not more than 5%.
Input
The first line is two integers n and a. 1<=n<=10^5.0.01< a < =0.35
Next n lines enter the mass Mi of n planets, guaranteeing 0<=mi<=10^7
Output
n rows, sequentially outputting the forces of each planet
Sample Input5 0.3
3
5
6
2
4Sample Output0.000000
0.000000
0.000000
1.968750
2.976000HINT
The exact result should be 0 0 0 2 3, but the result error of the sample output is not more than 5%, also
Source
Question: What is this problem ...
Notice that the important condition of the subject is the error, then the Nest Meng did a mess. Because when the planets are very far apart, the force is very small, it can be estimated that the distance from the former 1-now planet to the current planet is NOW/2, O (1) solved.
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn=100000+Ten; One Const Doubleeps=1e-8; A intNDoubleA,ANS[MAXN],M[MAXN],PRE[MAXN]; - voidinit () { -scanf"%D%LF",&n,&a); the for(intI=1; i<=n;i++) scanf ("%LF",&m[i]); - return; - } - voidWork () { + intnow=0; ans[1]=0.0; - intLim=min ( -, n); + for(intI=2; i<=lim;i++){ A if((Double) i*a+eps>= (Double) (now+1)) now++; at for(intj=1; j<=now;j++) ans[i]=ans[i]+m[i]*m[j]/(Double) (I-j); - } -pre[0]=0.0; for(intI=1; i<=n;i++) pre[i]=pre[i-1]+M[i]; - for(intI=2001; i<=n;i++){ - if((Double) i*a+eps>= (Double) (now+1)) now++; -ans[i]=pre[now]*m[i]/(Double) (I-(int) now/2); in } - return; to } + voidprint () { - for(intI=1; i<=n;i++) printf ("%.6lf\n", Ans[i]); the return; * } $ intMain () {init (); work ();p rint ();return 0;}
Bzoj 1011 [HNOI2008] a distant planet