QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#416726#5253. Denormalizationgalen_colin#TL 1ms3784kbC++171.2kb2024-05-22 04:21:072024-05-22 04:21:07

Judging History

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

  • [2024-05-22 04:21:07]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3784kb
  • [2024-05-22 04:21:07]
  • 提交

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

output:


result: