noip10

11.17

这场又是神人模拟赛。

大分题面。

t1

题意比Fwb模糊不清+inf。

赛后统计小样例2大家一共读出了6种答案。

感觉就是描述不清的detect。

读懂后纯简单题。

但有一车细节。

挂细节上了(代码中感叹号处)。

code

t1
#include <bits/stdc++.h>
#define pir pair<int, int>
#define ldb long double
#define fi first
#define se second
using namespace std;
const int N = 1e5 + 10;
const ldb eps = 1e-10;
int h, n;
pir a[N];
priority_queue<int> q;

inline int cmp(ldb a, ldb b)
{
    if (a - b > eps)
        return 1;
    if (b - a > eps)
        return -1;
    return 0;
}

signed main()
{
    freopen("water.in", "r", stdin);
    freopen("water.out", "w", stdout);
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    scanf("%d%d", &h, &n);
    bool f = 0;
    for (int i = 1; i <= n; ++i)
    {
        scanf("%d%d", &a[i].fi, &a[i].se); // t h
        if (!a[i].se)
            f = 1;
    }
    if (!f)
    {
        cout << -1;
        return 0;
    }
    sort(a + 1, a + 1 + n);

    ldb ans = 0, res = h;

    for (int i = 1; i <= n; ++i)
    {
        // cerr << "i=" << i << "\n";
        // printf("i=%d\n", i);
        ldb lim = a[i].fi - a[i - 1].fi;

        if (!q.size())
        {
            ans += lim;
            if (cmp(a[i].se, res) != 1) // a<=b
                q.push(a[i].se);
            // printf("res=%.6Lf ans=%.6Lf\n", res, ans);
            continue;
        }

        while (q.size())
        {
            ldb x = q.top();

            if (cmp(x, res) != -1)
            {
                // cout << "-----------------------------\n";
                // cout << "x=" << x << " res=" << res << "\n";
                // cout << "-----------------------------\n";
                q.pop();
                continue;
            }

            // cerr << "x=" << x << "\n";
            ldb tim = (res - x) / (ldb)q.size();
            // printf("tim=%.6Lf x=%Lf lim=%Lf\n", tim, x, lim);
            if (cmp(tim, lim) == 1)
            {
                ans += lim, res -= lim * (ldb)q.size();

                lim = 0; //!!!!!!!!!!!!!!!!!!!!!!!
                break;
            }
            else
            {
                ans += tim, res = x;
                q.pop();
                lim -= tim;
            }
            // printf("ans=%.6Lf\n", ans);
        }
        if (cmp(res, 0) != 1)
            break;
        ans += lim; //!!!!!!!!!!!!!!!!!!!!!
        // printf("ans=%.6Lf\n", ans);
        // printf("siz=%d res=%.6Lf ans=%.6Lf\n", (int)q.size(), res, ans);
        if (cmp(a[i].se, res) != 1)
            q.push(a[i].se);
    }

    // printf("res=%.6Lf ans=%.6Lf\n", res, ans);

    // cerr << "!\n";
    while (q.size())
    {
        if (cmp(res, 0) != 1)
            break;
        ldb x = q.top();
        ans += (ldb)(res - x) / (ldb)q.size();
        res = x;
        q.pop();
    }
    printf("%.6Lf", ans);
    return 0;
}

/*
detect
*/

t2

神人样例乱搞全过,水没边了。

正解dp

t3

不会数数。

t4

题面读假挂12.

只有部分分,不放代码了。

posted @ 2025-11-19 20:44  HS_fu3  阅读(8)  评论(0)    收藏  举报