求助,第3、4点没过。

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

lww0903 @ 2022-10-27 21:51:25

#include<stdio.h>
int main()
{int n,k,a[10000],sum1=0,sum2=0,n1=0,n2=0;
 scanf("%d%d",&n,&k);
 for(int i=1;i<n+1;i++)
 {a[i]=i;}
 for(int i=1;i<n+1;i++)
 {if(a[i]%k==0) 
  {sum1=sum1+a[i]; n1+=1;}
  else {sum2+=a[i]; n2+=1;}
  };
 printf("%0.1lf %0.1lf",1.0*sum1/n1,1.0*sum2/n2);
 return 0;}

by chenzhiyuan0923 @ 2022-10-27 21:58:44

@lww0903 迷之格式


by chenzhiyuan0923 @ 2022-10-27 21:59:08

#include<bits/stdc++.h>
using namespace std;
long long n,k,a[1000+10],cnt,a1,a2,x1,x2;
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++) {
        if(i%k==0) {
            a1+=i;
            x1++;
        }
        else{
            a2+=i;
            x2++;
        }
    }
    printf("%.1lf ",a1*1.0/x1);
    printf("%.1lf ",a2*1.0/x2);
    return 0;
}

by lww0903 @ 2022-10-28 10:37:17

@xchenzhiyuan 删了上边一个for循环之后过了,感谢佬


|