1 条题解

  • 0
    @ 2025-5-7 20:58:20

    题目分析

    本题要求根据星球半径、探测器汽油量以及与坠毁地点的角度,判断能否在燃料耗尽前往返坠毁地点。核心是计算往返路程,并与探测器可行驶距离比较。

    解题思路

    1. 数据读取与验证:读取起始行、输入行(星球半径(x)、汽油量(y)、角度(z))、结束行,验证起始行和结束行符合要求。
    2. 角度处理:若角度(z)大于(180)度,将其转换为(360 - z)度,保证计算的是较短路径的角度。
    3. 路程计算:根据圆周长公式(C = 2\pi r),结合角度(z)计算往返路程(a) ,即(a = 2\times\frac{z\times P\times x}{180}) 。
    4. 可行驶距离计算:探测器每加仑汽油行驶(5)英里,可行驶距离(b = y\times5) 。
    5. 结果判断与输出:比较可行驶距离(b)和往返路程(a) ,若(b < a) ,输出“NO”及可行驶距离(b)的整数部分;否则输出“YES”及剩余燃料量(c = y - \frac{a}{5})的整数部分。
    #include <stdio.h>
    #include <string.h>
    #define P 3.14159
    
    int main() {
        char str1[10], str2[10];
        int x, y, z;
    
        while (fgets(str1, sizeof(str1), stdin) && 
               scanf("%d %d %d\n", &x, &y, &z) == 3 && 
               fgets(str2, sizeof(str2), stdin)) {
            // Remove newline characters if present
            str1[strcspn(str1, "\n")] = '\0';
            str2[strcspn(str2, "\n")] = '\0';
    
            if (strcmp(str1, "START") == 0 && strcmp(str2, "END") == 0) {
                double a, b, c;
                if (z > 180) z = 360 - z;
                a = 2 * (z * P * x) / 180; // Total distance (round trip)
                b = y * 5;
                c = y - a / 5;
    
                if (b < a) {
                    printf("NO %d\n", (int)b);
                } else {
                    printf("YES %d\n", (int)c);
                }
            }
        }
        return 0;
    }
    • 1

    信息

    ID
    300
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    9
    已通过
    1
    上传者