1 条题解

  • 0
    @ 2023-6-21 19:58:06

    C++ :

    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #define INF 20005
    #define eps 1e-6
    #define maxn 100005
    using namespace std;
    struct glass{
        double t, c;
        glass(double t, double c) : t(t), c(c){}
        glass(){}
    }save[maxn];
    int dcmp(double a, double b){
        if (a - b > eps) return 1;
        else if (b - a > eps) return -1;
        return 0;
    }
    bool cmp(glass a, glass b){
        if (a.t != b.t) return dcmp(a.t, b.t) < 0;
        return dcmp(a.c, b.c) < 0;
    }
    double C, T;
    int n;
    bool judge(double x){
        double all = 0;
        for (int i = 0; i < n; i++){
            all += save[i].c * (x - save[i].t) / (T - x);
        }
        if (dcmp(C, all) >= 0) return true;
        return false;
    }
    double work(double l, double r){
        if (r - l < eps) return l;
        double mid = ((r - l) / 2) + l;
        if (judge(mid)) return work(mid, r);
        else return work(l, mid);
    }
    int main(){
        scanf("%d", &n);
        scanf("%lf%lf", &T, &C);
        for (int i = 0; i < n; i++){
            scanf("%lf%lf", &save[i].t, &save[i].c);
        }
        sort(save, save + n, cmp);
        if (dcmp(T, save[0].t) >= 0 && dcmp(T, save[n - 1].t) <= 0){
            for (int i = 0; i < n; i++){
                if(dcmp(T, save[i].t) != 0){
                    printf("Impossible\n");
                    return 0;
                }
            }
            printf("Possible\n%.4lf", save[0].t);
            return 0;
        }
        if (dcmp(T, save[0].t) < 0){
            if (judge(save[0].t)){
                printf("Possible\n%.4lf", save[0].t);
            }
            else printf("Impossible\n");
        }
        else{
            if (!judge(save[n - 1].t - eps)){
                printf("Impossible\n");
                return 0;
            }
            printf("Possible\n%.4lf", work(save[n - 1].t, T));
        }
        return 0;
    }
    
    • 1

    #6161. 「美团 CodeM 初赛 Round A」倒水

    信息

    ID
    1004
    时间
    1000ms
    内存
    32MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者