zoukankan      html  css  js  c++  java
  • BZOJ 1011 [HNOI2008]遥远的行星 (误差分析)

    1011: [HNOI2008]遥远的行星

    Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special Judge
    Submit: 4974  Solved: 1864
    [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

    HINT

      精确结果应该为0 0 0 2 3,但样例输出的结果误差不超过5%,也算对

     
    析:因为这个题误差不超过 5%,所以对于小数据我们就可以直接进行暴力,然后大数据我们就可以进行误差分析,A * j 得到一个数 t,我们就可以用 j - t / 2来代替所有的分母,这样的话就可以用前缀进行优化了,时间复杂度就小了,但是要注意这个题的是卡精度的,在求 t 的时候要加上一个eps,来控制精度。
    代码如下:
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <sstream>
    #include <list>
    #include <assert.h>
    #include <bitset>
    #include <numeric>
    #define debug() puts("++++")
    #define gcd(a, b) __gcd(a, b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define fi first
    #define se second
    #define pb push_back
    #define sqr(x) ((x)*(x))
    #define ms(a,b) memset(a, b, sizeof a)
    #define sz size()
    #define pu push_up
    #define pd push_down
    #define cl clear()
    #define all 1,n,1
    #define FOR(i,x,n)  for(int i = (x); i < (n); ++i)
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const LL LNF = 1e17;
    const double inf = 1e20;
    const double PI = acos(-1.0);
    const double eps = 1e-6;
    const int maxn = 1e5 + 10;
    const int maxm = 3e5 + 10;
    const int mod = 100003;
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, -1, 0, 1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline bool is_in(int r, int c) {
      return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    double sum[maxn];
    double b[maxn];
    
    int main(){
      double a;
      scanf("%d %lf", &n, &a);
      for(int i = 1; i <= n; ++i){
        scanf("%lf", b + i);
        sum[i] = sum[i-1] + b[i];
        double ans = 0.;
        int t = i * a + eps;
        if(i > 100){
          double xx = i - i * a / 2.;
          ans = sum[t] * 1. * b[i] / xx;
        }
        else {
          for(int j = 1; j <= t; ++j)
            ans += b[i] * 1. * b[j] / (i - j);
        }
        printf("%.6f
    ", ans);
      }
      return 0;
    }
    

      

  • 相关阅读:
    Webapi通过报文获取post上来的数据
    Jquery的跨域调用
    @html.ActionLink的几种参数格式
    MVC中使用RadioButtonFor
    string、Empty和null三者的区别
    JQuery中$.ajax()方法参数详解
    多线程与异步的区别
    IEnumerable,ICollection,IList,List之间的区别
    win10锁屏或睡眠一段时间后弹不出登录框
    ssh简明安全规划
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/7810220.html
Copyright © 2011-2022 走看看