1011: [hnoi2008] distant planet time limit: 10 sec memory limit: 162 mbsec Special Judge
Submit: 1852 solved: 633
[Submit] [Status] Description
There are n planets in a straight line, x = I at planet I, and planet J is subjected to the force of planet I, and only when I <= AJ. in this case, the size of the J force is fi-> J = mi * MJ/(J-I), where A is a small constant, therefore, intuitively, each planet is only affected by the distant planet. Calculate the force of each planet as long as the relative error of the result does not exceed 5%.
Input
The first line has two integers, N and A. 1 <= n <= 10 ^ 5.
1 <A <= 3.5 input mass mi of N planets in the next n rows to ensure 0 <= mi <= 10 ^ 7
Output
N rows, output the force of each planet in sequence
Sample input5 0.3
3
5
6
2
4
Sample output0.000000
0.000000
0.000000
1.968750
2.976000
Hint
The exact result should be 0 0 0 2 3, but the error of the output result of the sample cannot exceed 5%.
Question transport: http://hi.baidu.com/zeonsgtr/item/789da6f2838a3dc742c36ab7
God question, you can still calculate it like this...
Code:
1 const maxn=100000+1000; 2 var g:array[0..maxn] of int64; 3 f,m:array[0..maxn] of extended; 4 i,n:longint; 5 y:extended; 6 procedure init; 7 begin 8 readln(n,y); 9 for i:=1 to n do readln(m[i]);10 for i:=1 to n do g[i]:=trunc(i*y);11 end;12 procedure work1(x:longint);13 var i:longint;14 begin15 for i:=1 to g[x] do f[x]:=f[x]+m[x]*m[i]/(x-i);16 end;17 procedure work2(x:longint);18 var i:longint;19 begin20 f[x]:=(f[x-100]/m[x-100])*((x-100-g[x-100]/2)/(x-g[x-100]/2));21 for i:=g[x-100]+1 to g[x] do22 f[x]:=f[x]+m[i]/(x-i);23 f[x]:=f[x]*m[x];24 end;25 26 procedure main;27 begin28 for i:=1 to n do f[i]:=0.0;29 for i:=2 to n do30 if i<=500 then work1(i) else work2(i);31 for i:=1 to n do writeln(f[i]:0:6);32 end;33 begin34 assign(input,‘input.txt‘);assign(output,‘output.txt‘);35 reset(input);rewrite(output);36 init;37 main;38 close(input);close(output);39 end.
View code
T. Take 100 to pass. Where can we say that we have to output 6 decimal places...