bzoj 1011 遙遠的行星

來源:互聯網
上載者:User

標籤:

誤差 dp (什麼鬼)

讀題時覺得(誤差不超過 %5也算對) 這句話實在是沒有什麼卵用, 但是上這是解題的關鍵,因為兩個距離很遠的行星對答案的貢獻非常小,

所以我們可以讓一部分統一除以一個長度,為了保證精度的要求,前面的一部分要暴力算,這樣就可以過了

 1 #define MAXN 100010UL 2 #include <cmath> 3 #include <cstdio> 4 #include <algorithm> 5 #define eps 1e-7 6  7 using namespace std; 8  9 typedef long long ll;10 11 int n;12 ll sum[MAXN], M[MAXN];13 double A, f[MAXN];14 15 int main() {16     scanf("%d%lf", &n, &A);17     for(int i = 1 ; i <= n ; ++ i) scanf("%lld", &M[i]), sum[i] = M[i]+sum[i-1];18     for(int i = 1, r = min(2000, n) ; i <= r ; ++ i) {19         int k = (int)(i*A);20         if(fabs((k+1)/A-i)<eps) ++ k;21         for(int j = 1 ; j <= k ; ++ j) f[i] += M[i]*M[j]/(double)(i-j);22     }23     for(int i = 2001 ; i <= n ; ++ i) {24         int k = (int)(i*A), mid = (1+k)>>1;25         f[i] = sum[k]*M[i]/(double)(i-mid);26     }27     for(int i = 1 ; i <= n ; ++ i) printf("%lf\n", f[i]);28     return 0;29 }
View Code

 

bzoj 1011 遙遠的行星

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.