BensonQAQ @ 2020-10-15 21:35:21
代码
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n,k,k1=0,k2=0,A=0,B=0;
double s,t;
cin>>n>>k;
for(int i=1;i<=n;i++)
{
if(i%k==0)
{
k1+=i;
A++;
}
else
{
k2+=i;
B++;
}
}
s=k1/A*1.00;
t=k2/B*1.00;
printf("%0.1f %0.1f",s,t);
return 0;
}
by 李工男 @ 2020-10-17 10:06:16
平均数不对
s=k1/A1.00;
t=k2/B1.00;这样算的话是先除在乘,没有任何效果。
可以改成s=k11.00/A;t=k21.00/B;
修改后代码:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n,k,k1=0,k2=0,A=0,B=0;
double s,t;
cin>>n>>k;
for(int i=1;i<=n;i++)
{
if(i%k==0)
{
k1+=i;
A++;
}
else
{
k2+=i;
B++;
}
}
s=k1*1.00/A;
t=k2*1.00/B;
printf("%0.1f %0.1f",s,t);
return 0;
}
by 周鸿远 @ 2020-10-23 21:08:11
#include <iostream>
#include <stdio.h>
using namespace std;
int n, k, sum;
int main () {
scanf ("%d%d", &n, &k);
for (int i = k; i <= n; i += k)
sum += i;
printf ("%.1f ", double (sum) / (n / k));
sum = (1 + n) * n / 2 - sum;
printf ("%.1f\n", double (sum) / (n - n / k));
return 0;
}