QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#763298#6991. Rolling The Polygonhejinming983282#AC ✓1ms4404kbC++231.7kb2024-11-19 19:27:402024-11-19 19:27:41

Judging History

你现在查看的是最新测评结果

  • [2024-11-19 19:27:41]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:4404kb
  • [2024-11-19 19:27:40]
  • 提交

answer

// Author : hejinming2012
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define dbg(x) cout << #x " = " << (x) << endl
#define quickio ios::sync_with_stdio(false);
#define quickin cin.tie(0);
#define quickout cout.tie(0);
#define maxn 500005
using namespace std;
inline int read() {
	int now = 0, nev = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') nev = -1; c = getchar(); }
	while(c >= '0' && c <= '9') { now = (now << 1) + (now << 3) + (c & 15); c = getchar(); }
	return now * nev;
}
void write(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
struct node {
	double x, y;
};
node sub(const node &p1, const node &p2) {
	node res;
	res.x = p1.x - p2.x;
	res.y = p1.y - p2.y;
	return res;
}
double pro(const node &x, const node &y) {
	return x.x * y.x + x.y * y.y;
}
double cpro(const node &x, const node &y) {
	return fabs(x.x * y.y - x.y * y.x);
}
double dis(const node &x, const node &y) {
	double dx = x.x - y.x;
	double dy = x.y - y.y;
	return sqrt(dx * dx + dy * dy);
}
signed main() {
	quickio
	quickin
    quickout
	int T; cin >> T;
	for(int _ = 1; _ <= T; _++) {
		int n; cin >> n;
		vector <node> p(n);
		for(int i = 0; i < n; i++)
			cin >> p[i].x >> p[i].y;
		node q; cin >> q.x >> q.y;
		double tot = 0.0;
		for(int i = 0; i < n; i++) {
			int prev = (i + n - 1) % n;
			int nxt = (i + 1) % n;
			node A = sub(p[prev], p[i]);
			node B = sub(p[nxt], p[i]);
			double css = cpro(A, B);
			double dot = pro(A, B);
			double a = atan2(css, dot);
			double ea = 3.1415926535 - a;
			double d = dis(q, p[i]);
			tot += d * ea;
		}
		printf("Case #%lld: %.3lf\n", _, tot);
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4404kb

input:

4
4
0 0
2 0
2 2
0 2
1 1
3
0 0
2 1
1 2
1 1
5
0 0
1 0
2 2
1 3
-1 2
0 0
6
0 0
3 0
4 1
2 2
1 2
-1 1
1 0

output:

Case #1: 8.886
Case #2: 7.318
Case #3: 12.102
Case #4: 14.537

result:

ok 12 tokens

Test #2:

score: 0
Accepted
time: 1ms
memory: 4336kb

input:

50
9
685 -856
996 -558
867 151
120 882
-75 966
-997 967
-956 -628
-637 -933
500 -889
295 -63
11
288 942
-974 853
-867 -485
-730 -897
-614 -965
277 -860
509 -731
701 -517
816 -269
841 592
845 908
-50 -140
13
-911 97
-955 -496
-879 -852
-669 -959
572 -997
935 -782
957 -470
964 23
956 641
632 834
-137 ...

output:

Case #1: 7392.119
Case #2: 7185.680
Case #3: 8566.290
Case #4: 7558.260
Case #5: 8056.907
Case #6: 7822.441
Case #7: 8063.360
Case #8: 9438.598
Case #9: 9406.847
Case #10: 8038.276
Case #11: 8480.641
Case #12: 9868.279
Case #13: 7998.393
Case #14: 9059.588
Case #15: 8493.547
Case #16: 9569.443
Case ...

result:

ok 150 tokens