1 条题解

  • 1
    @ 2025-2-6 1:19:20

    学过一次函数的都会,没学过一次函数但学过 if 的也会。

    废话不多说,直接上代码:

    #include <bits/stdc++.h>
    using namespace std;
    double x; //浮点数!
    int main() {
        cin >> x;
        if (0 <= x && x < 5) printf("%.3f", 2.5 - x);
        /* "%.3f"表示保留小数点后 3 位 */
        else if (5 <= x && x < 10) printf("%.3f", 2 - 1.5 * (x - 3) * (x - 3));
        else printf("%.3f", x / 2 - 1.5);
        return 0;
    }
    

    第一次觉得 printf 这么好用^v^

    • 1

    信息

    ID
    4497
    时间
    1000ms
    内存
    128MiB
    难度
    1
    标签
    (无)
    递交数
    67
    已通过
    48
    上传者