P5719 水题
https://www.luogu.com.cn/problem/P5719
唠唠:别看这题很水,且只要求保留小数点后一位,倘若用float而不是double的话就无法AC,洛谷评测则只有40分。所以一定要用double!
总结:能用double就别用float
Code
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
int main()
{
int n,k,n1=0,n2=0;
double s1=0.0,s2=0.0;
cin>>n>>k;
for(int i=1;i<=n;i++)
{
if(i%k==0)
{
s1+=i;
n1++;
}
else
{
s2+=i;
n2++;
}
}
printf("%.1lf %.1lf",s1/n1,s2/n2);
return 0;
}