結果
| 問題 |
No.691 E869120 and Constructing Array 5
|
| ユーザー |
e869120
|
| 提出日時 | 2018-05-17 21:28:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 278 ms / 1,000 ms |
| コード長 | 2,158 bytes |
| コンパイル時間 | 1,127 ms |
| コンパイル使用メモリ | 93,264 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-28 14:48:06 |
| 合計ジャッジ時間 | 9,841 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ctime>
using namespace std;
struct State {
long double v; vector<int>t;
};
bool operator<(const State &a1, const State &a2) {
if (a1.v < a2.v) return true;
return false;
}
int Rand() {
return (1 << 20)*(rand() % 1024) + (1 << 10)*(rand() % 1024) + (rand() % 1024);
}
vector<int>concatenate(vector<int>A1, vector<int>A2) {
vector<int>I;
for (int i = 0; i < A1.size(); i++) I.push_back(A1[i]);
for (int i = 0; i < A2.size(); i++) I.push_back(A2[i]);
return I;
}
vector<int>solve(long double T) {
vector<State>F; int G1 = T / 8;
while (F.size() <= 100) {
int Y = Rand() % (G1*G1);
long double I = (T / 8) - sqrtl(1.0L*Y);
long double J = I*I; int K1 = J, K2 = K1 + 1;
long double L1 = sqrtl(1.0L*Y) + sqrtl(1.0L*K1); if (abs(T / 8 - L1) <= 1.0e-4) { F.push_back(State{ L1, vector<int>{Y, K1} }); }
long double L2 = sqrtl(1.0L*Y) + sqrtl(1.0L*K2); if (abs(T / 8 - L2) <= 1.0e-4) { F.push_back(State{ L2, vector<int>{Y, K2} }); }
}
sort(F.begin(), F.end()); long double EPS1 = T / 8, EPS = 1e-4;
for (int i = 0; i < 3; i++) {
vector<State>G; EPS1 *= 2.0L; EPS *= 0.01L;
for (int j = 0; j < F.size(); j++) {
long double R1 = (EPS1 - F[j].v);
int pos1 = lower_bound(F.begin(), F.end(), State{ R1,vector<int>{} }) - F.begin();
if (pos1 >= 1) {
long double Y = F[pos1 - 1].v + F[j].v;
if (abs(Y - EPS1) <= EPS) G.push_back(State{ Y,concatenate(F[pos1 - 1].t,F[j].t) });
}
if (pos1 < F.size()) {
long double Y = F[pos1].v + F[j].v;
if (abs(Y - EPS1) <= EPS) G.push_back(State{ Y,concatenate(F[pos1].t,F[j].t) });
}
}
F = G;
sort(F.begin(), F.end());
}
if (F.size() == 0) return vector<int>{};
return F[0].t;
}
int main() {
srand((unsigned)time(NULL));
int Q; cin >> Q;
for (int i = 1; i <= Q; i++) {
long double P; cin >> P;
vector<int>Z;
while (true) {
Z = solve(P); if (Z.size() >= 1) break;
}
long double E = 0;
cout << Z.size(); for (int j = 0; j < Z.size(); j++) { cout << " " << Z[j]; E += sqrtl(1.0L*Z[j]); }cout << endl;
//printf("score = %.13Lf\n", abs(P - E));
}
return 0;
}
e869120