1 条题解

  • 0
    @ 2025-9-16 20:19:52

    核心逻辑

    1. 计算总作业时间:共50天作业量,每天作业需x小时,总时间为 50 × x 小时;
    2. 计算日均所需时间(向上取整):需在30天内完成,日均时间为 (50x) / 30 = 5x/3 小时。由于需向上取整(即使小数部分不足1,也需多1小时),可通过整数运算公式简化:
      • 对正整数ab,向上取整a/b = (a + b - 1) // b(避免浮点数精度问题);
      • 此处a=5xb=3,故日均时间 = (5x + 3 - 1) // 3 = (5x + 2) // 3

    代码实现

    C

    #include <stdio.h>
    
    int main() {
        int x;
        scanf("%d", &x);
        // 整数运算实现向上取整:(5x + 2) // 3
        int result = (5 * x + 2) / 3;
        printf("%d\n", result);
        return 0;
    }
    

    C++

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        int x;
        cin >> x;
        int result = (5 * x + 2) / 3;
        cout << result << endl;
        return 0;
    }
    

    Python

    x = int(input())
    # 整数除法//实现向上取整
    result = (5 * x + 2) // 3
    print(result)
    
    • 1

    信息

    ID
    492
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    (无)
    递交数
    54
    已通过
    21
    上传者