跳到正文

题解

题解:P17003 [NWERC 2019] 极速魔方 / Expeditious Cubing

JohnWong约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年7月8日
收录
2026年7月10日
更新
2026年11月14日
篇幅
约 2 分钟
题目
P17003

版本

  1. v1当前

思路

设前四次成绩排序后为 a,b,c,da,b,c,d,第五次成绩为 xx,目标平均成绩为 TT。 要求剔除最大值、最小值后剩余三项平均值不超过 TT,记阈值 L=3TL = 3T。

分三类讨论有效求和:

  1. x≤ax \le a:剔除 x,dx,d,有效总和 S1=a+b+cS_1 = a+b+c。若 S1>LS_1 > L,无论 xx 多小都无法达标,输出 impossible。
  2. x≥dx \ge d:剔除 a,xa,x,有效总和 S2=b+c+dS_2 = b+c+d。若 S2≤LS_2 \le L,无论 xx 多大都能达标,输出 infinite。
  3. a<x<da < x < d:剔除 a,da,d,有效总和 b+c+x≤Lb+c+x \le L,解得最大允许用时:
xmax=L−b−cx_{\text{max}} = L - b - c
C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cout<<fixed<<setprecision(2);
    vector<double>v(4);
    for(int i=0;i<4;i++)cin>>v[i];
    double t;cin>>t;
    double l=3*t;
    sort(v.begin(),v.end());
    double a=v[0],b=v[1],c=v[2],d=v[3];
    double s1=a+b+c,s2=b+c+d;
    if(s1>l+1e-9)cout<<"impossible\n";
    else if(s2<=l+1e-9)cout<<"infinite\n";
    else cout<<l-b-c<<"\n";
    return 0;
}
原文
存档评论2 条抓取于