wwyxhqct @ 2023-05-30 19:38:20
测评详情
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int n, k, a1[5005], a2[5005], cnt1 = 0, cnt2 = 0, sum1 = 0, sum2 = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
if (i % k == 0) a1[++cnt1] = i;
else a2[++cnt2] = i;
}
for (int i = 1; i <= cnt1; i++) sum1 += a1[i];
for (int i = 1; i <= cnt2; i++) sum2 += a2[i];
cout << fixed << setprecision(1) << 1.0 * sum1 / cnt1 << " " << 1.0 * sum2 / cnt2;
return 0;
}
by Runtime_Error754 @ 2023-05-30 19:59:18
fixed,setprecision要写两次
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,s1,s2,p;
int main() {
cin>>n>>k;
for (int i = 1; i <= n; i++)
{
if (i%k==0) s1+=i,p++;
else s2+=i;
}
cout <<fixed<<setprecision(1)<<1.0*s1/p <<" "<<fixed<<setprecision(1)<<1.0*s2/(n-p);
return 0;
}