QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#329587#5104. Guardians of the Gallerycrimson231WA 11ms4036kbC++203.6kb2024-02-16 22:15:302024-02-16 22:15:32

Judging History

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

  • [2024-02-16 22:15:32]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:4036kb
  • [2024-02-16 22:15:30]
  • 提交

answer

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#define EPS 1e-9

struct Point {
  double x, y;
  Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}
  Point operator+(const Point& p) const { return {x+p.x, y+p.y}; }
  Point operator-(const Point& p) const { return {x-p.x, y-p.y}; }
  Point operator*(double c) const { return {x*c, y*c}; }
  Point operator/(double c) const { return {x/c, y/c}; }
  double Len() const { return hypot(x, y); }
};

inline double CrossProd(const Point& a, const Point& b) {
  return a.x*b.y - a.y*b.x;
}

inline double DotProd(const Point& a, const Point& b) {
  return a.x*b.x + a.y*b.y;
}

double RayIntersect(const Point& a, const Point& b, const Point& c, const Point& d, int* sides = NULL) {
  double cp1 = CrossProd(c-a, b-a), cp2 = CrossProd(d-a, b-a);
  double dp1 = DotProd(c-a, b-a), dp2 = DotProd(d-a, b-a);
  if (sides) *sides = (cp1 < -EPS || cp2 < -EPS) + 2 * (cp1 > EPS || cp2 > EPS);
  if (cp1 < -EPS && cp2 < -EPS || cp1 > EPS && cp2 > EPS) return -1.0;
  return (abs(cp1) < EPS && abs(cp2) < EPS) ? min(dp1, dp2) : (dp1*cp2-dp2*cp1)/(cp2-cp1);
}

bool PointOnLine(const Point& a, const Point& b, const Point& p) {
  double ln = (b-a).Len(), cp = CrossProd(b-a, p-a), dp = DotProd(b-a, p-a);
  return abs(cp/ln) < EPS && dp/ln > -EPS && dp/ln < ln+EPS;
}

int N;
vector<Point> p;

int main() {
  while (cin >> N) {
    p.resize(N+2);
    for (int i = 0; i < N+2; i++) cin >> p[i].x >> p[i].y;

    for (int i = 0; i < N+1; i++) {
      Point a = p[N+1], b = p[i];
      if ((b-a).Len() < EPS) { p.push_back(b); continue; }
      b = (b-a)/(b-a).Len() + a;
      vector<pair<double, int>> inter;
      for (int j = 0; j < N; j++) {
        int sides = 0;
        double rd = RayIntersect(a, b, p[j], p[(j+1)%N], &sides);
        if (rd < 0) continue;
        inter.push_back({rd, sides});
      }
      sort(inter.begin(), inter.end());
      double maxd = 0.0;
      for (int j = 0, sides = 0; sides != 3; j++) {
        maxd = inter[j].first;
        sides |= inter[j].second;
      }
      p.push_back((b-a)*maxd + a);
      for (int j = 0; j <= N; j++) {
        double rd = RayIntersect(a, b, p[j], p[j]+Point(b.y-a.y, a.x-b.x)*1.1e3);
        if (rd < 0) rd = RayIntersect(a, b, p[j], p[j]+Point(a.y-b.y, b.x-a.x)*1.1e3);
        if (rd > EPS && rd < maxd-EPS) p.push_back((b-a)*rd + a);
      }
    }

    vector<double> dist(p.size(), 1e10);
    priority_queue<pair<double, int>> q;
    q.push({0.0, N});
    for (;;) {
      int i = q.top().second;
      if (i > N) break;
      double d = -q.top().first;
      q.pop();
      if (d >= dist[i]) continue;
      dist[i] = d;
      for (int j = 0; j < p.size(); j++) {
        Point a = p[i], b = p[j];
        double ln = (b-a).Len();
        int ni = 0;
        if (ln < EPS) goto pass;
        if (i < N && PointOnLine(p[i], p[(i+1  )%N], p[j])) goto pass;
        if (i < N && PointOnLine(p[i], p[(i+N-1)%N], p[j])) goto pass;
        b = (b-a)/ln + a;
        for (int k = 0; k < N; k++) {
          double rd = RayIntersect(a, b, p[k], p[(k+1)%N]);
          if (rd > EPS && rd < ln-EPS) goto fail;
        }
        a = (p[i]+p[j])/2;
        b = a+Point(cos(42), sin(42));
        for (int k = 0; k < N; k++) {
          double rd = RayIntersect(a, b, p[k], p[(k+1)%N]);
          ni += (rd > EPS);
        }
        if (ni%2 == 0) goto fail;
pass:   q.push({-d-ln, j});
fail:;
      }
    }
    printf("%.12lf\n", -q.top().first);
  }
}

詳細信息

Test #1:

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

input:

15
13 7
20 20
39 20
49 7
73 13
100 5
117 38
98 20
80 20
66 40
68 20
51 20
41 39
22 48
2 39
10 20
104 20

output:

29.000000000000

result:

ok found '29.0000000', expected '29.0000000', error '0.0000000'

Test #2:

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

input:

16
39 2
48 22
39 41
20 51
20 68
40 66
20 80
20 98
38 117
5 100
13 73
7 49
19 39
20 23
20 20
7 13
20 10
20 104

output:

13.000000000000

result:

ok found '13.0000000', expected '13.0000000', error '0.0000000'

Test #3:

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

input:

16
13 33
20 60
23 66
39 97
49 105
73 166
100 205
117 272
98 216
80 180
66 172
68 156
51 122
41 121
22 92
2 44
10 40
104 228

output:

140.872282582486

result:

ok found '140.8722826', expected '140.8722826', error '0.0000000'

Test #4:

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

input:

16
64 17
50 28
67 23
65 18
77 4
88 20
78 10
70 29
61 28
47 32
54 17
43 13
35 20
41 30
27 20
42 6
81 12
33 23

output:

64.204537702523

result:

ok found '64.2045377', expected '64.2045377', error '0.0000000'

Test #5:

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

input:

16
64 17
50 28
67 23
65 18
77 4
88 20
78 10
70 29
61 28
47 32
54 17
43 13
35 20
41 30
27 20
42 6
33 23
81 12

output:

72.283498041177

result:

ok found '72.2834980', expected '72.2834980', error '0.0000000'

Test #6:

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

input:

7
76 8
389 215
691 19
407 331
489 397
300 403
363 334
126 60
393 370

output:

6.657917756511

result:

ok found '6.6579178', expected '6.6579178', error '0.0000000'

Test #7:

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

input:

3
0 1000
1000 0
1000 1000
567 578
589 601

output:

-0.000000000000

result:

ok found '-0.0000000', expected '0.0000000', error '0.0000000'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

3
0 1000
0 0
1000 0
366 366
367 366

output:

-0.000000000000

result:

ok found '-0.0000000', expected '0.0000000', error '0.0000000'

Test #9:

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

input:

5
50 93
278 178
199 300
596 362
208 519
421 388
142 153

output:

175.169759391735

result:

ok found '175.1697594', expected '175.1697594', error '0.0000000'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3980kb

input:

7
50 93
278 178
199 300
401 312
483 162
596 362
208 519
488 252
142 153

output:

289.682139876890

result:

ok found '289.6821399', expected '289.6821399', error '0.0000000'

Test #11:

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

input:

8
10 10
40 25
20 25
20 35
12 23
30 23
10 20
5 40
15 15
19 26

output:

25.000000000000

result:

ok found '25.0000000', expected '25.0000000', error '0.0000000'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3924kb

input:

9
5 1000
6 3
5 999
0 1000
0 0
500 2
500 0
1000 0
1000 1000
1 4
993 1

output:

5.101047906986

result:

ok found '5.1010479', expected '5.1010479', error '0.0000000'

Test #13:

score: 0
Accepted
time: 11ms
memory: 4036kb

input:

100
695 43
538 87
463 208
597 329
750 306
812 481
960 555
912 344
983 450
987 573
994 852
941 985
801 855
792 800
849 806
792 696
924 701
939 672
710 546
722 668
723 807
715 767
624 524
634 554
547 503
357 352
627 458
651 495
937 558
932 545
864 509
753 489
509 397
341 335
300 495
199 528
380 688
48...

output:

1695.186573023643

result:

ok found '1695.1865730', expected '1695.1865730', error '0.0000000'

Test #14:

score: -100
Wrong Answer
time: 1ms
memory: 3852kb

input:

20
840 854
839 45
996 905
959 938
852 938
730 423
425 493
136 481
213 778
527 740
691 941
22 830
83 313
462 155
636 21
462 321
360 324
238 422
402 492
806 406
952 822
410 838

output:

1425.156530598248

result:

wrong answer 1st numbers differ - expected: '1424.3842015', found: '1425.1565306', error = '0.0005422'