QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#666759 | #5253. Denormalization | jay248 | WA | 0ms | 4180kb | C++14 | 1.6kb | 2024-10-22 19:51:09 | 2024-10-22 19:51:19 |
Judging History
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