quell @ 2024-09-05 19:26:37
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,k;
double sum1=0,sum2=0,ans1=0,ans2=0;
cin>>n,k;
for(int i=1;i<=n;i++)
{
if(i/k==0) {
sum1+=i;
ans1++;
}
else
{
sum2+=i;
ans2++;
}
}
cout<<fixed<<setprecision(1)<<sum1/ans1<<" "<<sum2/ans2;
return 0;
}
by LeNotFound @ 2024-09-05 19:29:25
if里边应该用%吧 @quell
by quell @ 2024-09-05 19:30:04
@LeNotFound 哦哦好嘟,我试试
by quell @ 2024-09-05 19:31:55
@LeNotFound 可是还是WA鸭
by quell @ 2024-09-05 19:33:19
#include <bits/stdc++.h>
using namespace std;
int main(){
double sum1=0,sum2=0,ans1=0,ans2=0;
int n,k;
cin>>n,k;
for(int i=1;i<=n;i++)
{
if(i%k==0) {
sum1+=i;
ans1++;
}
else
{
sum2+=i;
ans2++;
}
}
cout<<fixed<<setprecision(1)<<sum1/ans1<<" "<<sum2/ans2;
return 0;
}
唔,还是错的
by TigerXiaoxi @ 2024-09-05 19:53:07
@quell
#include <bits/stdc++.h>
using namespace std;
int main(){
double sum1=0,sum2=0,ans1=0,ans2=0;
int n,k;
cin>>n,k;
for(int i=1;i<=n;i++)
{
if(i%k==0) {
sum1+=i;
ans1++;
}
else
{
sum2+=i;
ans2++;
}
}
printf("%.1lf %.1lf",sum1/ans1,sum2/ans2);
return 0;
}
试试
by LeNotFound @ 2024-09-05 20:00:18
@quell <<fixed<<setprecision(1)
只对后边紧接着的一个输出有效哦
by llhhss @ 2024-09-05 21:11:02
@quell
#include<iostream>
#include<cstdio>
using namespace std;
int n,k,cnt1=0,cnt2=0;
double ans1,ans2,sum1,sum2;
int main(){
cin>>n;
cin>>k;
for(int i=1;i<=n;i++){
if(i%k==0){
sum1+=i;
cnt1++;
}else{
sum2+=i;
cnt2++;
}
}
ans1=sum1/cnt1;
ans2=sum2/cnt2;
printf("%.1lf %.1lf",ans1,ans2);
return 0;
}
by quell @ 2024-09-06 19:31:27
@LeNotFound 好滴,谢谢你/qq
by quell @ 2024-09-06 19:31:43
@llhhss thx
by llhhss @ 2024-09-07 14:17:53
@quell ?