__Cow__ @ 2022-02-18 19:57:07
RT,这份代码我写了两遍,因为第一遍的ans会报错,所以又写了一遍。
翻了翻题解,好像有人写的像我的。
#include <bits/stdc++.h>
using namespace std;
int n,k;
int num1,num2;
int sum1,sum2;
double ans1,ans2;
int main()
{
scanf ("%d %d", &n, &k);
for (int i=1;i<=n;i++)
{
if (i%k==0)
{
num1+=i;
sum1++;
}
else
{
num2+=i;
sum2++;
}
}
ans1 = num1/sum1;
ans2 = num2/sum2;
printf ("%.1lf %.1lf\n",ans1,ans2);
return 0;
}
by __Cow__ @ 2022-02-18 20:04:49
#2 in:
1000 7
#2 out:
500.5 500.5
by dxy2020 @ 2022-02-18 20:10:59
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
scanf ("%d%d",&n,&k);
int s=(n+1)*n/2;
double sum=0;double cnt=0;
cnt=(floor)(n/k);
sum=(cnt+1)*cnt/2*k;
printf ("%.1lf %.1lf",sum/cnt,(s-sum)/(n-cnt));
return 0;
}
O1代码
by dxy2020 @ 2022-02-18 20:11:14
对照改一下