m3o7o2n1 @ 2024-02-05 19:46:57
#include <stdio.h>
int main(){
int n,k,a[100000],b[100000],j,t,i,sum1=0,sum2=0;
float x,y;
scanf("%d %d",&n,&k);
for(i=1,j=0,t=0;i<=n;i++){
if(i%k==0){
a[j]=i;
j=j+1;
}
else {
b[t]=i;
t=t+1;
}
}
for(int p=0;p<j;p++)sum1=sum1+a[p];
for(int p=0;p<t;p++)sum2=sum2+b[p];
x=sum1/j;
y=sum2/t;
printf("%.1f %.1f",x,y);
return 0;
}
by Wilderness_ @ 2024-02-05 20:03:19
#include <stdio.h>
int main(){
int n,k,a[100000],b[100000],j,t,i,sum1=0,sum2=0;
float x,y;
scanf("%d %d",&n,&k);
for(i=1,j=0,t=0;i<=n;i++){
if(i%k==0){
a[j]=i;
j=j+1;
}
else {
b[t]=i;
t=t+1;
}
}
for(int p=0;p<j;p++)sum1=sum1+a[p];
for(int p=0;p<t;p++)sum2=sum2+b[p];
x=sum1*1.0/j;
y=sum2*1.0/t;//这里要先*1.0,不然算出来会是一个整数的值
printf("%.1f %.1f",x,y);
return 0;
}