BZOJ - 1011【乱搞】

1011: [HNOI2008]遥远的行星

Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special Judge
Submit: 4075  Solved: 1514
[Submit][Status][Discuss]

Description

  直线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=
Mi*Mj/(j-i) 其中A为很小的常量,故直观上说每颗行星都只受到距离遥远的行星的作用。请计算每颗行星的受力
,只要结果的相对误差不超过5%即可.

Input

  第一行两个整数N和A. 1<=N<=10^5.0.01< a < =0.35,接下来N行输入N个行星的质量Mi,保证0<=Mi<=10^7

Output

  N行,依次输出各行星的受力情况

Sample Input

5 0.3
3
5
6
2
4

Sample Output

0.000000
0.000000
0.000000
1.968750
2.976000

题解:乱搞就是了,刚开始5e5*1000以为不超时,找错边界了,后来AC了;

代码:

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <bitset>
 6 #include <vector>
 7 #include <queue>
 8 #include <stack>
 9 #include <cmath>
10 #include <list>
11 #include <set>
12 #include <map>
13 #define rep(i,a,b) for(int i = a;i <= b;++ i)
14 #define per(i,a,b) for(int i = a;i >= b;-- i)
15 #define mem(a,b) memset((a),(b),sizeof((a)))
16 #define FIN freopen("in.txt","r",stdin)
17 #define FOUT freopen("out.txt","w",stdout)
18 #define IO ios_base::sync_with_stdio(0),cin.tie(0)
19 #define mid ((l+r)>>1)
20 #define ls (id<<1)
21 #define rs ((id<<1)|1)
22 #define N 100005
23 #define INF 0x3f3f3f3f
24 #define INFF ((1LL<<62)-1)
25 using namespace std;
26 typedef long long LL;
27 typedef pair<int, int> PIR;
28 const double eps = 1e-8;
29   
30 int n;
31 double A, m[N], ans[N], sum[N];
32 int main()
33 {
34     //FIN;
35     scanf("%d %lf", &n, &A);
36     for(int i = 1; i <= n; ++i){
37         scanf("%lf", &m[i]);
38         sum[i] = sum[i-1] + m[i];
39         //a[i] = A*double(i)+eps;
40     }
41     for(int i = 1;i <= n; ++i){
42         int t = A*double(i)+eps;
43         if(t > 200){
44             int len = i-t/2;
45             ans[i] += sum[t-200]*m[i]/len;
46             for(int j = t-200;j <= t;++ j)
47                 ans[i] += m[i]*m[j]/(i-j);
48         }
49         else{
50             for(int j = 1;j <= t;++ j)
51                 ans[i] += m[i]*m[j]/(i-j);
52         }
53     }
54     for(int i = 1; i <= n; ++ i)    
55         printf("%.6lf\n", ans[i]);
56     return 0;
57 }
View Code

 

posted on 2017-02-03 20:41  Jstyle  阅读(154)  评论(0编辑  收藏  举报

导航