1 条题解

  • 0
    @ 2025-4-9 21:01:33

    1. 输入理解

    • 输入由多行组成,每行包含一个多项式和一个 x 的值。多项式由其最高次幂 maxPower 和从最高次幂到常数项的系数(其中最高次幂的系数 an始终为 1)表示,最后是变量 x 的值。输入以 maxPower和 an 都为 0 作为结束标志。
    • 例如,输入 3 1 0 1 11 1 表示多项式 x^3 + 0x^2 + 1x + 11,其中 x = 1。

    完整代码

    #include <stdio.h>
    #include <iostream>
    #include <vector>
    #include <string>
    #include <stack>
    #include <iomanip>
    #include <algorithm>
    #include <queue>
    #include <functional>
    using namespace std;
     
    const int MAX_N = 1005;
     
    int N;
    int men[MAX_N][MAX_N];
    int women[MAX_N][MAX_N];
    int point[MAX_N][MAX_N];
    int menChoose[MAX_N];
    vector<int> choosed[MAX_N];
     
    int getDigits(int n) {
        int d = 0;
        while (n) {
            d++;
            n /= 10;
        }
        return d;
    }
     
    int main() {
     
        std::ios::sync_with_stdio(false);
     
        int maxPower, an, x, last;
        int c[105];
        int counter = 0;
     
        while (1) {
            counter++;
            cin >> maxPower >> an;
            if (maxPower == 0 && an == 0) break;
            for (int i = maxPower - 1; i >= 1; i--) {
                cin >> c[i];
            }
            cin >> last >> x;
            int ans = x;
            int cost = 0;
            for (int i = maxPower - 1; i >= 1; i--) {
                if (c[i]) {
                    cost += 2;
                    cost += getDigits(c[i]);
                } else {
                    cost++;
                }
                ans = (ans + c[i]) * x;
            }
            ans += last;
            if (last) {
                cost += maxPower + 2 + getDigits(last);
            } else {
                cost += maxPower + 1;
            }
            if (maxPower) {
                cout << "Polynomial " << counter << ": " << ans << " " << cost << endl;
            } else {
                cout << "Polynomial " << counter << ": " << 1 << " " << 2 << endl;
            }
        }
     
        return 0;
    }
    
    • 1

    信息

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