When n is greater than a certain range, approximate values are taken
1011: [HNOI2008] Distant Planet time limit: ten Sec Memory Limit: 162 mbsec Special Judge
Submit: 2350 Solved: 837
[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
#include <iostream> #include <cstring> #include <cmath> #include <cstdio> #include < algorithm>using namespace Std;const int Maxn=100100;const double eps=1e-8;int n;double a;double M[MAXN]; Double PRE[MAXN];d ouble ans[maxn];int Main () {scanf ("%d%lf", &n,&a), for (int i=1;i<=n;i++) {scanf ("%lf", M+i );p re[i]=pre[i-1]+m[i];} Ans[1]=0;int now=0;for (int i=2;i<=min (2000,n); i++) {while (double) i*a+eps>= (double) (now+1)) now++;for (int j=1 ; j<=now;j++) {ans[i]+=m[i]*m[j]/(double) (I-J);}} for (int i=2001;i<=n;i++) {while (double) i*a+eps>= (double) (now+1)) now++;ans[i]=pre[now]*m[i]/(double) (I-( int) NOW/2);} for (int i=1;i<=n;i++) {printf ("%.8f\n", Ans[i]);} return 0;}
Bzoj 1011: [HNOI2008] a distant planet