None_g @ 2023-05-31 17:34:10
代码如下
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k,A[1000],B[1000],C[10001],x,m,j,X,M,o,p;
float a,b;
cin>>n>>k;
o=0;
p=0;
for (m=1;m<=n;m++)
{
C[m]=m;
}
x=1;
j=1;
for (m=1;m<=n;m++)
{
if (C[m]%k==0)
{
A[x]=C[m];
x++;
}
else
{
B[j]=C[m];
j++;
}
}
for (X=1;X<=x;X++)
{
o+=A[X];
}
for (M=1;M<=x;M++)
{
p+=B[M];
}
a=o/X;
b=p/M;
cout<<a<<" "<<b;
return 0;
}
救救
by midsummer_zyl @ 2023-06-24 21:47:00
实话实说,我也不知道你哪里出差错了(主要因为我也只是只小菜鸟),直接给你看我的代码罢:
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, k;
double s1 = 0, s2 = 0, sum1 = 0, sum2 = 0;
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i++) {
if(i % k == 0) {
s1 += i;
sum1++;
}
else {
s2 += i;
sum2++;
}
}
printf("%.1lf %.1lf", s1 / sum1 * 1.0, s2 / sum2 * 1.0);
return 0;
}