QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#270285 | #7753. Energy Distribution | ucup-team859# | WA | 952ms | 3792kb | C++14 | 2.8kb | 2023-11-30 18:06:54 | 2023-11-30 18:06:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
using ll = long long;
using ull = unsigned long long;
string to_string(const string &s) {
return '"' + s + '"';
}
string to_string(bool b) {
return b ? "true" : "false";
}
template <typename A, typename B>
string to_string(const pair<A, B> &p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(const T &v) {
string s = "{";
bool first = true;
for (const auto &it : v) {
if (!first)
s += ", ";
else
first = false;
s += to_string(it);
}
return s += "}";
}
void debug_out() {
cerr << endl;
}
template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
cerr << to_string(first) << " ";
debug_out(rest...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
auto startTime = high_resolution_clock::now();
int get_time() {
auto stopTime = chrono::high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stopTime - startTime);
return duration.count(); // in ms
}
using ld = long double;
const ld eps = 1e-6;
int n;
int w[11][11];
ld eval(vector<ld> &p) {
ld sum = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j)
sum += p[i] * p[j] * w[i][j];
}
return sum;
}
void norm(vector<ld> &p) {
ld sum = 0;
for (int i = 1; i <= n; ++i)
sum += p[i];
for (int i = 1; i <= n; ++i)
p[i] /= sum;
}
ld run_regr(vector<ld> &p) {
while (get_time() <= 950) {
ld best = eval(p), df;
int pos = -1;
vector<ld> aux = p;
for (int i = 1; i <= n; ++i) {
p[i] += eps;
norm(p);
ld res = eval(p);
if (res > best) {
best = res;
df = eps;
pos = i;
}
p = aux;
p[i] -= eps;
if (p[i] >= 0) {
norm(p);
ld res = eval(p);
if (res > best) {
best = res;
df = -eps;
pos = i;
}
}
p = aux;
}
if (pos == -1)
return best;
p[pos] += df;
norm(p);
}
return eval(p);
}
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
cin >> w[i][j];
}
}
vector<ld> p(n + 1, 0);
ld best = 0;
while (get_time() <= 900) {
auto dis = uniform_real_distribution<ld>(0, 1);
for (int i = 1; i <= n; ++i)
p[i] = dis(rng);
norm(p);
best = max(best, run_regr(p));
}
cout << fixed << setprecision(20) << best << "\n";
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 913ms
memory: 3792kb
input:
2 0 1 1 0
output:
0.24999999999999941202
result:
ok found '0.2500000', expected '0.2500000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 908ms
memory: 3540kb
input:
3 0 2 1 2 0 2 1 2 0
output:
0.57142857142857087183
result:
ok found '0.5714286', expected '0.5714290', error '0.0000004'
Test #3:
score: 0
Accepted
time: 952ms
memory: 3648kb
input:
3 0 1 2 1 0 1 2 1 0
output:
0.49999999999998840500
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #4:
score: 0
Accepted
time: 952ms
memory: 3576kb
input:
4 0 3 1 0 3 0 1 0 1 1 0 2 0 0 2 0
output:
0.74999999558666056765
result:
ok found '0.7500000', expected '0.7500000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 951ms
memory: 3736kb
input:
5 0 0 0 4 4 0 0 2 0 4 0 2 0 2 0 4 0 2 0 0 4 4 0 0 0
output:
0.99999975928281223029
result:
ok found '0.9999998', expected '1.0000000', error '0.0000002'
Test #6:
score: 0
Accepted
time: 951ms
memory: 3688kb
input:
6 0 9 5 5 10 6 9 0 0 0 0 1 5 0 0 0 3 0 5 0 0 0 10 5 10 0 3 10 0 0 6 1 0 5 0 0
output:
2.85714090887218751685
result:
ok found '2.8571409', expected '2.8571430', error '0.0000007'
Test #7:
score: -100
Wrong Answer
time: 952ms
memory: 3660kb
input:
7 0 0 0 0 50 10 45 0 0 0 0 0 3 1 0 0 0 0 0 4 16 0 0 0 0 44 0 0 50 0 0 44 0 37 6 10 3 4 0 37 0 2 45 1 16 0 6 2 0
output:
12.51157028871538398531
result:
wrong answer 1st numbers differ - expected: '12.5115850', found: '12.5115703', error = '0.0000012'