QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#416726 | #5253. Denormalization | galen_colin# | TL | 1ms | 3784kb | C++17 | 1.2kb | 2024-05-22 04:21:07 | 2024-05-22 04:21:07 |
Judging History
answer
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define int long long
#define double long double
using namespace std;
const int N = 1e8;
const double EPS = 1e-4;
mt19937 rng(123);
bool isEqual(double a, double b){
return abs(a-b) <= EPS;
}
signed main(){
fastio
int n;
cin >> n;
vector<double> v, vv;
double sum = 0;
for(int i = 0; i < n; i++){
double x;
cin >> x;
v.push_back(x);
sum += x;
}
for(auto &x : v) x /= sum;
vv = v;
int idx = 0, now = 1;
shuffle(v.begin(), v.end(), rng);
bool done = false;
while(!done){
for(int i = now; i <= N; i += now){
if(isEqual(v[idx] * i, round(v[idx] * i))){
now = i;
break;
}
}
done = true;
for(int i = 0; i < n; i++){
if(!isEqual(v[i] * now, round(v[i] * now))){
done = false;
idx = i;
break;
}
}
}
for(int i = 0; i < n; i++){
cout << round(vv[i] * now) << "\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3784kb
input:
2 0.909840249060 0.414958698174
output:
1423 649
result:
ok good solution
Test #2:
score: -100
Time Limit Exceeded
input:
3 0.005731604132 0.696198848562 0.717826101486