Leaf59 @ 2024-07-27 11:59:31
#include<bits/stdc++.h>
using namespace std;
int n,k;
double a,b,c,d;
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
if(i%k==0){
a+=i;
c++;}
else {
b+=i;
d++;}
}
cout<<a/c*1.0<<" "<<b/d/1.0;
return 0;
}
哪里有问题?
by haimingbei @ 2024-07-27 12:03:24
@Leaf59 精确到小数点后 1 位,仔细省题!!!
by Leaf59 @ 2024-07-27 12:05:42
@haimingbei 怎么改?
by haimingbei @ 2024-07-27 12:05:46
@Leaf59
#include<bits/stdc++.h>
using namespace std;
int n,k;
double a,b,c,d;
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
if(i%k==0){
a+=i;
c++;}
else {
b+=i;
d++;}
}
cout<<fixed<<setprecision(1)<<a/c*1.0<<" ";
cout<<fixed<<setprecision(1)<<b/d*1.0;
return 0;
}
by haimingbei @ 2024-07-27 12:06:06
@Leaf59
by Leaf59 @ 2024-07-27 12:08:11
@haimingbei
谢谢!
回关
就
by guoyanwei120223 @ 2024-08-09 17:22:25
#include<bits/stdc++.h>
using namespace std;
int n,k;
double a,b,c,d;
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
{
if(i%k==0)
{
a+=i;
c++;
}
else
{
b+=i;
d++;
}
}
cout<<fixed<<setprecision(1)<<a/c*1.0<<" ";
cout<<fixed<<setprecision(1)<<b/d*1.0;
return 0;
}
求关
by SBGL @ 2024-08-11 20:16:54
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<windows.h>
const int N=2;
int n,k,a[N],y,z=0;
double f,g;
int main(){
std::cin>>n>>k;
for(int i=1;i<=n;++i){
if(i%k==0) {y++; f+=i;}
if(i%k!=0) {z++; g+=i;}
}
printf("%.1lf %.1lf",f/y,g/z);
return 0;
}
by Leaf59 @ 2024-08-14 18:33:09
@SBGL 谢了
by llhhss @ 2024-09-05 21:24:25
@Leaf59 不能用@SBGL的代码
#include<windows.h>
这个库洛谷网站不支持
by llhhss @ 2024-09-05 21:25:32
@SBGL
#include<windows.h>
洛谷网站不支持此库