http://oj.acm.zstu.edu.cn/JudgeOnline/problem.php?cid=4034&pid=11

C++版本一

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#define eps 1e-8
#define ll long long
const int INF = 0x3f3f3f3f;
const long long mod=1e9+7;
const int N=105;
using namespace std;
int main()
{
    ll n,ans;
    while(~scanf("%lld",&n))
    {
        if(n<=2)
        {
            printf("0\n");
            continue;
        }
        if(n>=2000)
        {
            printf("250\n");
            continue;
        }
        ll a=(n-2)/2;
        ll b=(n-1)/2;
        if(b>a)
           ans=b*b;
        else
           ans=b*(b+1);
        double k1=1000.0/((n-1)*1.0);
        double k2=1000.0/(n*1.0);
        double kk=k1-k2;
        double mm=kk*(double)ans;
        mm+=0.500;
        printf("%lld\n",(ll)mm);
    }
}

C++版本二

题解:有公式法,但是比赛时想着直接模拟打表(擦掉,超时了才想的打表),500是极限不要问我为什么,慢慢试的 (ಥ_ಥ) 

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
 
int v[1000];
 
int main(){
    int n,i;
    for(i=3;i<=500;i++){
        double old=1000./i,ne=1000./(i-1),fir=(2*old-ne)/2;
        int cnt=(i-1)/2,j;
        double sum=fir,last=fir,next;
        for(j=2;j<=cnt;j++){
            next=last+old-ne;
            sum+=next;
            last=next;
        }
        v[i]=2*sum+0.5;
    }
    while(~scanf("%d",&n)){
        if(n>500){
            printf("250\n");
            continue;
        }
        printf("%d\n",v[n]);
    }
    return 0;
}