QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#466659#8524. Weather ForecastEl_7la2een#WA 0ms4056kbC++20873b2024-07-08 00:21:202024-07-08 00:21:21

Judging History

你现在查看的是最新测评结果

  • [2024-07-08 00:21:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4056kb
  • [2024-07-08 00:21:20]
  • 提交

answer


#include<bits/stdc++.h>
using namespace std;
int n, k;

bool check(vector<double>& v, double avg) {

    double sum = 0, num = 0;
    int cnt = 0;
    for (auto& i : v) {
        sum += i;
        num++;

        double av = sum / num;

        if (avg <= av) {
            cnt++;
            sum = 0;
            num = 0;
        }
    }

    return (cnt >= k);
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


    cin >> n >> k;

    vector<double>v(n);
    for (auto& i : v)cin >> i;

    double l = 0, r = 10000;

    double ans = 0;
    for (int i = 0; i < 60; i++) {
        double md = (l + r) / 2.0;
        if (check(v, md)) {
            ans = md;
            l = md;
        }
        else r = md;
    }

    cout << fixed << setprecision(12) << ans << "\n";
return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3808kb

input:

7 3
1 3 1 2 2 2 1

output:

1.666666666667

result:

ok found '1.66667', expected '1.66667', error '0.00000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 4056kb

input:

1 1
1

output:

1.000000000000

result:

ok found '1.00000', expected '1.00000', error '0.00000'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3944kb

input:

2 1
2 1

output:

2.000000000000

result:

wrong answer 1st numbers differ - expected: '1.50000', found: '2.00000', error = '0.50000'