QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666747#5253. Denormalizationjay248WA 1ms4228kbC++141.8kb2024-10-22 19:49:032024-10-22 19:49:23

Judging History

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

  • [2024-10-22 19:49:23]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4228kb
  • [2024-10-22 19:49:03]
  • 提交

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;
}

// Function to find the smallest integer multiplier c for m such that m * c is close to an integer
int find_multiplier(double m) {
    for (int c = 1; c <= 10000; c++) {
        double val = m * c;
        if (fabs(val - round(val)) < 1e-9) {  // Check if the value is close to an integer
            return c;
        }
    }
    return -1;  // This should not happen
}

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 LCM of all multipliers
    int lcm = 1;
    for (int i = 0; i < n; i++) {
        int multiplier = find_multiplier(x[i]);
        lcm = (lcm * multiplier) / gcd(lcm, multiplier);
    }

    // Step 2: Multiply each element by the LCM and round to the nearest integer
    int result[100005];
    for (int i = 0; i < n; i++) {
        result[i] = static_cast<int>(round(x[i] * lcm));
    }

    // Step 3: Ensure that the GCD of the result is 1
    int overall_gcd = result[0];
    for (int i = 1; i < n; i++) {
        overall_gcd = gcd(overall_gcd, result[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++) {
            result[i] /= overall_gcd;
        }
    }

    // Output the reconstructed integers
    for (int i = 0; i < n; i++) {
        cout << result[i];
        if (i < n - 1) {
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4228kb

input:

2
0.909840249060
0.414958698174

output:

1 0

result:

wrong answer Integer parameter [name=r_i] equals to 0, violates the range [1, 10000]