QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666759#5253. Denormalizationjay248WA 0ms4180kbC++141.6kb2024-10-22 19:51:092024-10-22 19:51:19

Judging History

你现在查看的是最新测评结果

  • [2024-10-22 19:51:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4180kb
  • [2024-10-22 19:51:09]
  • 提交

answer

#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>

using namespace std;

int n;
double x[100005];

// Function to compute the GCD of two numbers
int gcd(int a, int b) {
    while (b != 0) {
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

int main() {
    // Input number of elements
    cin >> n;
    
    // Input normalized values
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    // Step 1: Find the smallest element in the list (which corresponds to the smallest original integer)
    double min_val = 1.0;
    for (int i = 0; i < n; i++) {
        if (x[i] < min_val) {
            min_val = x[i];
        }
    }

    // Step 2: Scale all elements by dividing them by the smallest element
    int scaled_values[100005];
    for (int i = 0; i < n; i++) {
        scaled_values[i] = static_cast<int>(round(x[i] / min_val)); // Scale and round to get integer values
    }

    // Step 3: Ensure that the GCD of the result is 1
    int overall_gcd = scaled_values[0];
    for (int i = 1; i < n; i++) {
        overall_gcd = gcd(overall_gcd, scaled_values[i]);
    }

    // If the GCD is greater than 1, divide all elements by the GCD
    if (overall_gcd > 1) {
        for (int i = 0; i < n; i++) {
            scaled_values[i] /= overall_gcd;
        }
    }

    // Step 4: Output the scaled values
    for (int i = 0; i < n; i++) {
        cout << scaled_values[i];
        if (i < n - 1) {
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 4180kb

input:

2
0.909840249060
0.414958698174

output:

2 1

result:

wrong answer incorrect solution