求助qaq

P5719 【深基4.例3】分类平均

__我谔谔__ @ 2020-02-26 19:20:25

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    double flag1=0,flag2=0;
    double a,b;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        if(i%k==0) 
        {
            a+=i;
            flag1++;
        }
        else
        {
            b+=i;
            flag2++;
        }
    }
    cout<<fixed<<setprecision(1)<<a/flag1<<' ';
    cout<<fixed<<setprecision(1)<<b/flag2;
    return 0;
}

by tangrunxi @ 2020-02-26 19:22:11

@嘿哈哈哈哈哈 这题数据好像有锅


by __我谔谔__ @ 2020-02-26 19:22:43

@tangrunxi 谢谢


by P31pr @ 2020-02-26 19:33:47

草这道题好像没人过???


by Gunpowder_OI @ 2020-02-26 19:35:15

haoxiangjiushi


by Gunpowder_OI @ 2020-02-26 19:36:06

我用了防除以0的方法做的还是这样

#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n, k, suma = 0, sumb = 0;
    double resa = 0;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        if (i % k == 0)suma += i, resa ++;
        else sumb += i;
    }
    if (resa == n)cout << fixed << setprecision (1) << suma / resa << " " << 0.0;
    else if (resa == 0)cout << fixed << setprecision (1) << 0.0 << " " << sumb / (n - resa);
    else cout << fixed << setprecision (1) << suma / resa << " " << sumb / (n - resa);
    return 0;
}

by PersistentLife @ 2020-02-26 19:42:11

数据有锅


by 节操永动机 @ 2020-02-26 19:43:22

数据有问题吧大概


by lzqy_ @ 2020-02-26 19:56:11

数据的问题


by sochiji @ 2020-02-26 20:05:23

我刚交了一发,过了。是不是数据被修正了?


by cq_loves_Capoo @ 2020-02-26 20:12:39

没锅,你们没判断0


| 下一页