"bzoj1011" [HNOI2008] a distant planet

Source: Internet
Author: User

1011: [HNOI2008] Distant planet time limit:10 Sec Memory limit:162 mbsec Special Judge
submit:3711 solved:1375
[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. The size of the Force J is fi->j=
mi*mj/(J-i) where a is a very small constant, 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

"Spit Groove"

The provincial election actually exam such a hole problem ...

"As long as the relative error of the result is not more than 5%," This is the key word.

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. (Is this a greedy strategy?) )

How to Improve IQ??? It's a permanent topic.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <cstdlib>6#include <ctime>7#include <algorithm>8 using namespacestd;9 #defineMAXN 100010Ten #defineEPS 1e-8 One intN; A DoubleA,M[MAXN],SUM[MAXN],ANS[MAXN]; -InlineintRead () - { the     intx=0, f=1;CharCh=GetChar (); -      while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} -      while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} -     returnx*F; + } - intMain () + { AN=read (); scanf"%LF", &a); sum[0]=0.000000; at      for(intI=1; i<=n;i++) {scanf ("%LF", &m[i]); sum[i]=sum[i-1]+m[i];} -      for(intI=1; I<=min ( -, n); i++) -     { -         intR=eps+floor (A *i); -          for(intj=1; j<=r;j++) ans[i]+=m[i]*m[j]/(i-j); -     } in      for(intI=2001; i<=n;i++) -     { to         intR=eps+floor (A *i); +ans[i]+=sum[r]*m[i]/(Double) (I-(int) r/2); -     } the      for(intI=1; i<=n;i++) printf ("%6lf\n", Ans[i]); *     return 0; $}

"bzoj1011" [HNOI2008] a distant planet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.