Cannis_GU @ 2022-03-25 12:00:51
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<math.h>
using namespace std;
int main(){
double n,k,a[10000],m=0,x=0,y=0;
cin>>n>>k;
for(int i=1;i<=n;i++){
a[i]=i;
}
for(int j=1;j<=n;j++){
if(a[j]%k==0){
m+=a[j];
x++;
}
}
for(int j=1;j<=n;j++){
if(a[j]%k!=0){
y+=a[j];
}
}
y=m/(n-x);
x=m/x;
cout<<fixed<<setprecision(1)<<x;
cout<<" ";
cout<<fixed<<setprecision(1)<<y;
}
by Jasper08 @ 2022-03-25 12:09:41
@Cannis_GU 你这缩进有问题啊(
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
int n = 0, k = 0;
cin >> n >> k;
double aver1 = 0, aver2 = 0;
int i = k;
for (; i <= n; i += k)
aver1 += i;
i = i / k - 1;
aver1 /= i;
for (int j = 1; j <= n; j++)
aver2 += j;
aver2 -= aver1 * i;
aver2 /= (n - i);
printf("%.1f %.1f", aver1, aver2);
return 0;
}
by Cannis_GU @ 2022-03-25 12:31:25
@Jasper08 因为我是直接在提交页面写的,没注意呢。谢谢啦!