QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369005#5253. DenormalizationNYCU_template#WA 1ms3916kbC++141.1kb2024-03-27 19:18:432024-03-27 19:18:45

Judging History

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

  • [2024-03-27 19:18:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3916kb
  • [2024-03-27 19:18:43]
  • 提交

answer

#include <bits/stdc++.h>
#define MP make_pair
#define F first
#define S second
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;

const int LIMIT = 10000;

const double eps = 1e-9;

struct vecs {
	double d;
	int ans, idx;
} a[10000];

pii getVal(double a, double b) {
	for (int i = 1; i <= LIMIT; i++) {
		double x = b / (a / i);
		if (abs(x - round(x)) < eps) {
			return MP(i, round(x));
		}
	}
	return MP(-1, -1);
}

int lcm(int a, int b) {
	return ll(a) * b / __gcd(a, b);
}

int main() {
	int n, base = 1;
	pii rat[10000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].d;
		a[i].idx = i;
	}
	sort(a, a + n, [](const vecs &x, const vecs &y){
			return x.d < y.d;
		});
	for (int i = 1; i < n; i++) {
		rat[i] = getVal(a[0].d, a[i].d);
		base = lcm(base, rat[i].F);
	}
	a[0].ans = base;
	for (int i = 1; i < n; i++) {
		a[i].ans = rat[i].S * base / rat[i].F;
	}
	sort(a, a + n, [](const vecs &x, const vecs &y){
			return x.idx < y.idx;
		});
	for (int i = 0; i < n; i++) {
		cout << a[i].ans << "\n";
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
0.909840249060
0.414958698174

output:

1
1

result:

wrong answer incorrect solution