QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#298867 | #7903. Computational Intelligence | ucup-team087# | WA | 1238ms | 4120kb | C++14 | 3.0kb | 2024-01-06 15:19:02 | 2024-01-06 15:19:03 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
using Double = double;
constexpr Double EPS = 1e-12;
constexpr int N = 400;
static_assert(N % 2 == 0);
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
Double X[4][2];
for (int i = 0; i < 4; ++i) for (int j = 0; j < 2; ++j) {
int x;
scanf("%d", &x);
X[i][j] = x;
}
for (int j = 0; j < 2; ++j) X[1][j] -= X[0][j];
for (int j = 0; j < 2; ++j) X[3][j] -= X[2][j];
auto calc = [&](Double s) -> Double {
Double a = 0.0, b = 0.0, c = 0.0;
for (int j = 0; j < 2; ++j) {
// ((X[2][j] + X[3][j] t) - (X[0][j] + X[1][j] s))^2
const Double f = X[3][j];
const Double g = X[2][j] - (X[0][j] + X[1][j] * s);
a += f*f;
b += 2*f*g;
c += g*g;
}
const Double l = b / (2*a);
const Double r = b / (2*a) + 1;
const Double sa = sqrt(a);
const Double d = (c - b*b / (4*a)) / a;
if (d <= EPS) {
auto sub = [&](Double u) -> Double {
return sa * u*u/2;
};
if (0 <= l) {
return sub(r) - sub(l);
} else if (r <= 0) {
return sub(l) - sub(r);
} else {
return sub(l) + sub(r)/* - 2 * sub(0)*/;
}
} else {
auto sub = [&](Double u) -> Double {
const Double su = sqrt(u*u + d);
return sa * (u * su - d * log(su - u)) / 2;
};
return sub(r) - sub(l);
}
};
Double ans = 0.0;
for (int i = 0; i <= N; ++i) {
const Double res = calc(1.0 / N * i);
ans += ((i == 0 || i == N) ? 1 : (i % 2 == 0) ? 2 : 4) * res;
}
ans /= N;
ans /= 3;
printf("%.12f\n", ans);
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4028kb
input:
3 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 1 0 0 1 1 1
output:
0.333333333333 0.765195716781 1.076635732895
result:
ok 3 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 4120kb
input:
3 0 1 0 0 0 -1 0 2 0 0 1 0 2 0 -1 0 -1000 0 0 999 0 -998 999 0
output:
0.777777777778 0.777777777778 1521.070405024268
result:
ok 3 numbers
Test #3:
score: -100
Wrong Answer
time: 1238ms
memory: 4028kb
input:
100000 -4 -10 -8 -8 5 5 -10 -8 -10 10 -1 -3 -3 5 -1 -3 8 -7 8 -10 0 -3 0 10 6 -1 0 2 0 -3 3 1 -6 -5 5 3 3 5 -4 -8 1 9 1 -1 2 -1 -6 0 1 -2 -7 -9 -1 -2 -4 5 6 -10 7 1 0 -6 -8 -8 -10 9 2 3 -7 -10 4 -9 8 4 4 9 -9 3 0 4 5 -2 9 8 -9 -5 7 8 -1 1 0 1 -4 1 -8 1 3 3 10 3 3 0 -6 -2 -3 -3 -3 3 -2 7 -10 -7 9 2 6...
output:
9.028267617369 5.744131450097 14.594278702892 2.952178258532 4.993502697336 6.058717216200 7.459408700235 11.228028907916 16.325707847496 11.072245157189 9.504557451149 5.500000000000 9.040049985831 5.326347910887 3.035934371282 5.808804086288 17.363719789522 9.995194519237 6.993302622881 6.55043322...
result:
wrong answer 4th numbers differ - expected: '2.9521782', found: '2.9521783', error = '0.0000000'