cf1009 C. Annoying Present

注意这道题对于每个数字都加x,如果不加会搞错

然后如果d是正数往两边放,负数往中间放

一开始没读懂题目,费了好多时间

#include<bits/stdc++.h>
using namespace std;
long long res=0;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int x,d;
        scanf("%d%d",&x,&d);
        long long tmp;
        if(d>=0)
        {
            tmp=1LL*(1+n-1)*(n-1)/2;
        }
        else
        {
            if(n%2==0)
              tmp=1LL*(1+n/2)*(n/2)/2+1LL*(1+n/2-1)*(n/2-1)/2;
            else if(n%2==1)
              tmp=2LL*(1+n/2)*(n/2)/2;
        }
        res+=(1LL*x*n+1LL*tmp*d);
    }
    double ans=(double)res/n;
    printf("%.8lf\n",ans);
}

猜你喜欢

转载自www.cnblogs.com/lishengkangshidatiancai/p/10322554.html