#救救孩子##只能过两个测试点

P5719 【深基4.例3】分类平均

double_blue @ 2022-10-26 19:37:12

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    int n,k,i=1;
    float sum1=0,sum2=0,n1=0,n2=0;
    cin>>n>>k;
    sum1=(k-1)*k/2;
    n1=k-1;
    i=k;
    while(i<=n)
    {   
        if(i%k!=0)
        { 
          sum1+=i;
          n1++;
        }
        i++;
    }
    sum2=(1+n)*n/2-sum1;
    n2=n-n1;
    cout<<setiosflags(ios::fixed)<<setprecision(1)<<sum2/n2<<' '<<sum1/n1<<endl;
    return 0;
}

|