chenmumin @ 2023-07-20 19:14:54
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,a[10005],q=0;
double ping1=0,quan;
scanf("%d%d",&n,&k);
for(int i=1;i<n;i++){
if(i%k==0){
// a[q]=i;
q++;
ping1=ping1+i;
}
}
// cout<<ping1<<" ";
double ans1=ping1/q;
printf("%.1f ",ans1);
for(int i=1;i<=n;i++){
quan=quan+i;
}
double ans2=(quan-ping1)/(n-q);
printf("%.1f",ans2);
}
by YC_Aldrich @ 2023-07-20 19:26:48
你第一个n没有遍历到
for(int i=1;i<n;i++){//是 <= n
if(i%k==0){
// a[q]=i;
q++;
ping1=ping1+i;
}
}
而且quan 没有初始化
by YC_Aldrich @ 2023-07-20 19:28:58
@chenmumin
by chenmumin @ 2023-07-20 19:34:20
@yinxiang080508 ok