1011: [HNOI2008]遥远的行星

题目链接

题目大意:有一些行星,求受到的引力

题解:正常暴力是O(n^2)的,n方过10万?wys……发现题目要求误差%5,乱搞,暴力计算前面的,后面的近似……

我的收获:我觉得我应该去学一下浮点精度误差……

#include 
using namespace std;
double m[100005], sum[100005];
int main()
{
    int n;
    double a, ans;
    scanf("%d%lf", &n, &a);
    for(int j = 1; j <= n; ++j)
    {
        int i = (int)(a * j + 1e-8);
        scanf("%lf", m + j);
        ans = 0;
        if(j <= 500)
            for(int k = 1; k <= i; ++k)
                ans += m[k] * m[j] / (j - k);
        else
            ans = sum[i] * m[j] / (j - i / 2);
        printf("%f\n", ans);
        sum[j] = sum[j - 1] + m[j];
    }
    return 0;
}

你可能感兴趣的:(1000-1250)