Tarshine @ 2023-03-27 15:07:53
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k,sum1=0,sum2=0;
double ave1,ave2;
cin>>n>>k;
for(int i=k;i<=n;i+=k) sum1+=i;
sum2=(n+1)*n/2-sum1;
ave1=sum1/(n/k);
ave2=sum2/(n-n/k);
cout<<fixed<<setprecision(1)<<ave1<<" "<<ave2;
return 0;
}
by manyc @ 2023-04-02 14:36:23
@Tu15879030589 你可能中间转换出了点问题,我没细看,ACcode:
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int n,k;
double a=0.0,b=0.0,ai=0.0,bi=0.0;
cin>>n>>k;
for(int i=1;i<=n;i++){
if(i%k==0){
a+=double(i);
ai+=1.0;
}else{
b+=double(i);
bi+=1.0;
}
}
cout<<fixed<<setprecision(1)<<a/ai<<" ";
cout<<fixed<<setprecision(1)<<b/bi;
return 0;
}