数不一样啊

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

zhuzihan0903 @ 2024-07-30 13:42:37

#include<bits/stdc++.h>
using namespace std;
int main(){
    double n,k,sum=0;
    cin>>n>>k;
    for(int i=k;i<=n;i+=k)
    {
        sum+=i;
    } 
    printf("%.1f ",sum/(n/k));
    sum=(1+n)*n/2-sum;
    printf("%.1f\n",sum/(n-n/k));
    return 0;
}

by haimingbei @ 2024-07-30 13:52:46

@zhuzihan0903

AC,求关

#include<bits/stdc++.h>
using namespace std;
int n,k;
double a,b,c,d;
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        if(i%k==0){
        a+=i;
        c++;}
        else {
        b+=i;
        d++;}
    }
    cout<<fixed<<setprecision(1)<<a/c*1.0<<" ";
    cout<<fixed<<setprecision(1)<<b/d*1.0;
    return 0;
}

by zhuzihan0903 @ 2024-08-01 12:21:30

@haimingbei 已关


|