bzoj1011: [HNOI2008] Distant planets

topic link

bzoj1011: [HNOI2008] Distant planets

answer

emmm probability question
I have done a min_hash trick before, I have time to sort it out (
the upper limit of pit a is 0.35
\(f_i=\sum_{j=1}^{a\times{i}}\frac{m_i\times{ m_j}}{ij}\)
Violent and complex (n*0.35n)
can't pass .
For an i, if O1 can be obtained, \(\sum_{j = 1}^{a*i} \frac{1} The approximate value of {ij} / i * a\)
can be calculated using the prefix of m and O1 and
found that the range of j is \([1,a \times{i})\)
Let - \(a\times{i} \over 2\) This fixed value is replaced with
the upper limit of the denominator a of the above formula, 0.35. When i increases, the denominator becomes larger and larger, and the error becomes smaller and smaller.
Then you can calculate when i increases to when the error is less than 5%, smaller than this i is violent, when it is bigger....

code

#include<cstdio>
#include<algorithm> 
int n;
#define eps 1e-8
const int maxn = 100005;
double a,f[maxn],m[maxn];  
double sum[maxn]; 
int main() { 
    scanf("%d%lf",&n,&a); 
    for(int i = 1;i <= n;++ i) scanf("%lf",m + i),sum[i] =sum[i - 1] + m[i]; 
    for(int i = 1;i <= n;++ i) {
        int t = int(a * i + eps); 
        if(i <= 500)  
            for(int j = 1;j <= t;++ j) 
                f[i] += m[i] * m[j] / (i - j); 
 
        else f[i] += sum[t] * m[i] / double ((i - t / 2 )) ;
    }
    for(int i = 1;i <= n;++ i) {
        printf("%lf\n",f[i]); 
    } 
    return 0; 
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325943729&siteId=291194637