QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#58003 | #4838. Rotate Sum 2 | MIT01# | WA | 3ms | 3928kb | C++17 | 900b | 2022-10-24 08:47:09 | 2022-10-24 08:47:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr const double PI = acos(-1.0);
ll x[100005], y[100005];
ll sx2, sx, sy2, sy;
double ans1, ans2;
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lld%lld", x+i, y+i);
sx2 += x[i]*x[i], sx += x[i];
sy2 += y[i]*y[i], sy += y[i];
}
x[n] = x[0], y[n] = y[0];
x[n+1] = x[1], y[n+1] = y[1];
// area of polygon
for (int i = 0; i < n; i++) {
ans1 += x[i]*y[i+1]-x[i+1]*y[i];
}
ans1 /= 2;
// sectors
for (int i = 1; i <= n; i++) {
double dot = (x[i+1]-x[i])*(x[i-1]-x[i]) + (y[i+1]-y[i])*(y[i-1]-y[i]);
double angle = acos(dot / hypot(x[i+1]-x[i], y[i+1]-y[i]) / hypot(x[i-1]-x[i], y[i-1]-y[i]));
ans2 += (PI - angle) * (n*x[i]*x[i] + n*y[i]*y[i] - 2*sx*x[i] - 2*sy*y[i] + sx2 + sy2);
}
ans2 /= 2*n;
printf("%.17lf\n", ans1+ans2);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3888kb
input:
3 1 -1 1 1 -1 2
output:
18.76323450317391917
result:
ok found '18.76323', expected '18.76323', error '0.00000'
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3928kb
input:
4 -1000000000 1000000000 -1000000000 -1000000000 1000000000 -1000000000 1000000000 1000000000
output:
2078331698204927232.00000000000000000
result:
wrong answer 1st numbers differ - expected: '16566370614359173120.00000', found: '2078331698204927232.00000', error = '0.87455'