QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#537461 | #5254. Differences | UESTC_DECAYALI# | TL | 0ms | 0kb | C++20 | 1010b | 2024-08-30 13:56:08 | 2024-08-30 13:56:09 |
answer
#include<bits/stdc++.h>
using namespace std;
using LD = long double;
const int N = 1e4+5;
const LD eps = 5e-7;
int n, r[N], ans[N];
LD A[N], rt[N];
int gcd(int a, int b){return 0==b ? a : gcd(b, a%b);}
LD check(){
int d = 0;
for (int i=1; i<=n; ++i) d += r[i]*r[i];
LD dt = sqrtl(d);
for (int i=1; i<=n; ++i) rt[i] = r[i]/dt;
LD res = 1e30;
for (int i=1; i<=n; ++i){
res = min(abs(rt[i] - A[i]), res);
}
return res;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
int mn=1;
for (int i=1; i<=n; ++i){
cin >> A[i];
if (A[i] < A[mn]) mn=i;
}
LD minv = 1e30;
for (int i=1; i<=n; ++i){
LD res = i / A[mn];
for (int j=1; j<=n; ++j) r[j] = round(A[j]*res);
LD rs = check();
if(rs < minv) minv = rs, memcpy(ans, r, sizeof(int) * (n + 1));
}
for (int i=1; i<=n; ++i){
cout << ans[i] << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
3585 4096 2048 ABBBBBBAABAAAAAAAAAAAAABAABABBBABABAAAAABABAAAABAABAABBABBAABAABABBABAABBABBABABABBAAAABBABAABBBBABBBAABBBBBABAABAAABAAABBBBAAAABAABAABABABABBBBBABAAABAAABBAABABBABAABBAABBAABABBBBAABAAAABAABBABAAABBAAAAAABAABBABBABAABABBBAABABBABABBBAAAAABBBABABABBAABAAAABBBBABABAABBBABABABBAABBBABAB...