The magical idea of Qaq
Maya saw this problem I was drunk, what thing ... Error of 5%? Decisive worship of the @ydc god Ben:
Just because you don't know how to apply that answer, the error is no more than 5%.
I have never seen such a strange problem before, and asked the method is still doubtful, until later found really effective.
is less than 2000, we n^2 explosion, more than 2000, because α is very small, I is more than 2000, so i-ixα is very large, accurate said 1/(i-1) and 1/(i-ixα) almost large ...
So for I, greater than 2000, if he can get K, we just have to change the formula in the I-j are I-K/2 on it, the error will not be very large.
In addition, it is not possible to write directly (int) (a*i), because when α=0.350000,i=20 I calculated a 6 ... So, a sentence.
1 /**************************************************************2 problem:10113 User:tunix4 language:c++5 result:accepted6 time:1652 Ms7 memory:3616 KB8 ****************************************************************/9 Ten //Bzoj 1011 One#include <cmath> A#include <vector> -#include <cstdio> -#include <cstring> the#include <cstdlib> -#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) + #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + #definePB Push_back A using namespacestd; atInlineintGetint () { - intv=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*Sign ; - } in Const intn=1e5+Ten, inf=~0u>>2; - Const Doubleeps=1e-7; totypedefLong LongLL; + /******************tamplate*********************/ - intN; the LL M[n],sum[n]; * DoubleF[n],a; $ intMain () {Panax Notoginseng #ifndef Online_judge -Freopen ("1011.in","R", stdin); theFreopen ("1011.out","W", stdout); + #endif Ascanf"%D%LF",&n,&a); theF (I,1, N) { +scanf"%lld",&m[i]); -sum[i]=sum[i-1]+M[i]; $ } $D (I,min (N, -),1){ - intK= (int) (A *i); - if(Fabs (Double) (k +1) (/a-i) <eps) k++; theF (J,1, k) f[i]=f[i]+m[i]*m[j]/(Double) (I-j); - }WuyiF (I,2001, N) { the intK= (int) (A*i), mid= (1+K) >>1; -f[i]=sum[k]*m[i]/(Double) (I-mid); Wu } -F (I,1, N) printf ("%lf\n", F[i]); About return 0; $}
View Code 1011: [HNOI2008] Distant planet time limit:10 Sec Memory limit:162 mbsec Special Judge
submit:2302 solved:820
[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 [Submit] [Status] [Discuss]
"Bzoj" "1011" "HNOI2008" Distant planets