QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#279656#7846. Glacier Travelbachbeo2007AC ✓9ms6948kbC++234.5kb2023-12-08 22:51:022023-12-08 22:51:05

Judging History

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

  • [2023-12-08 22:51:05]
  • 评测
  • 测评结果:AC
  • 用时:9ms
  • 内存:6948kb
  • [2023-12-08 22:51:02]
  • 提交

answer

/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;

const int mxN = 2e5 + 5;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const i64 oo = 1e18;

template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
    typedef Point P;
    T x, y;
    explicit Point(T x=0, T y=0) : x(x), y(y) {}
    bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
    bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
    P operator+(P p) const { return P(x+p.x, y+p.y); }
    P operator-(P p) const { return P(x-p.x, y-p.y); }
    P operator*(T d) const { return P(x*d, y*d); }
    P operator/(T d) const { return P(x/d, y/d); }
    T dot(P p) const { return x*p.x + y*p.y; }
    T cross(P p) const { return x*p.y - y*p.x; }
    T cross(P a, P b) const { return (a-*this).cross(b-*this); }
    T dist2() const { return x*x + y*y; }
    double dist() const { return sqrt((double)dist2()); }
    // angle to x-axis in interval [-pi, pi]
    double angle() const { return atan2(y, x); }
    P unit() const { return *this/dist(); } // makes dist()=1
    P perp() const { return P(-y, x); } // rotates +90 degrees
    P normal() const { return perp().unit(); }
    P scale(T val) const { return *this / dist() * val; }
    // returns point rotated 'a' radians ccw around the origin
    P rotate(double a) const {
        return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
    friend ostream& operator<<(ostream& os, P p) {
        return os << "(" << p.x << "," << p.y << ")"; }
};

typedef Point<double> P;

int n;
double x;
P a[mxN];

void solve() {
    cin >> x >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i].x >> a[i].y;

    int cidx1 = 2, cidx2 = -1;
    double cdis = 0.0;
    P cur1 = a[1], cur2;
    for (int i = 2; i <= n; ++i) {
        cdis += (a[i] - a[i - 1]).dist();
        if (cdis > x) {
            cdis -= (a[i] - a[i - 1]).dist();
            cidx2 = i, cur2 = (a[i] - a[i - 1]).scale(x - cdis) + a[i - 1];
            break;
        }
    }
    cout << fixed << setprecision(12);
    if (cidx2 == -1) {
        cout << (a[1] - a[n]).dist() << endl;
        return;
    }
    double res = oo;
    while (cidx2 <= n) {

        // cout << cidx1 << " " << cur1 << endl;
        // cout << cidx2 << " " << cur2 << endl;

        res = min(res, (cur1 - cur2).dist());
        double dis1 = (a[cidx1] - cur1).dist(), dis2 = (a[cidx2] - cur2).dist();
        double maxx = min(dis1, dis2);
        double l = 0, r = maxx;

        // cout << maxx << endl;

        auto get = [&](double val) {
            P point1 = (a[cidx1] - cur1).scale(val) + cur1;
            P point2 = (a[cidx2] - cur2).scale(val) + cur2;
            return (point1 - point2).dist();
        };

        while (r - l > eps) {
            double mid1 = l + (r - l) / 3;
            double mid2 = l + (r - l) / 3 * 2;
            if (get(mid1) > get(mid2)) l = mid1;
            else r = mid2;
        }
        res = min(res, get(l));
        res = min(res, get(r));

        if (abs(dis1 - dis2) <= eps) {
            ++cidx1, ++cidx2;
            cur1 = a[cidx1 - 1], cur2 = a[cidx2 - 1];
        }
        else if (dis1 < dis2) {
            ++cidx1, cur1 = a[cidx1 - 1];
            cur2 = (a[cidx2] - cur2).scale(dis1) + cur2;
        }
        else {
            ++cidx2, cur2 = a[cidx2 - 1];
            cur1 = (a[cidx1] - cur1).scale(dis2) + cur1;
        }
        // cout << endl;
    }
    cout << res << endl;
}

signed main() {

#ifndef CDuongg
    if(fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) solve();

#ifdef CDuongg
   auto end = chrono::high_resolution_clock::now();
   cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
   cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif

}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 6892kb

input:

5
4
20 0
10 0
10 10
0 10

output:

3.535533905933

result:

ok found '3.53553', expected '3.53553', error '0.00000'

Test #2:

score: 0
Accepted
time: 2ms
memory: 6780kb

input:

3.16227766
9
-2 4
2 4
3 1
4 4
5 1
6 4
10 2
6 1
7 4

output:

1.000000000000

result:

ok found '1.00000', expected '1.00000', error '0.00000'

Test #3:

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

input:

20
5
9 38
36 16
-5 36
-24 15
30 37

output:

2.293595760356

result:

ok found '2.29360', expected '2.29360', error '0.00000'

Test #4:

score: 0
Accepted
time: 2ms
memory: 6948kb

input:

10
40
17 18
12 -5
12 -16
-10 16
7 -15
18 -18
19 15
-19 1
-18 11
-8 -12
-17 -12
5 -12
-15 -8
-10 -10
-4 4
-2 -3
15 17
-2 -9
-13 7
-12 17
15 -3
-19 -14
6 6
14 -5
-10 -15
17 -16
-11 15
9 -6
10 8
19 -1
12 -6
-18 2
14 17
9 -7
-8 -3
7 11
-12 -14
-19 4
-1 15
-17 16

output:

0.000000069296

result:

ok found '0.00000', expected '0.00000', error '0.00000'

Test #5:

score: 0
Accepted
time: 2ms
memory: 6840kb

input:

10
40
10 11
11 15
6 -16
-18 4
10 10
-10 16
-17 11
2 6
-6 -9
17 -7
-7 -5
10 -18
-9 9
-14 10
19 -3
-14 -3
15 -5
-3 16
-10 14
-9 -12
10 -18
10 -4
-9 -11
11 -2
9 2
12 15
2 -17
-8 -16
19 7
-19 -2
-17 7
16 -9
6 -6
8 -18
15 9
17 2
-19 12
-15 -9
1 -15
19 -12

output:

0.344214437307

result:

ok found '0.34421', expected '0.34421', error '0.00000'

Test #6:

score: 0
Accepted
time: 9ms
memory: 6728kb

input:

1000
4000
-720538 -681604
667325 347504
-911397 -962007
-264075 -858319
49605 149209
964851 361021
-397274 28661
-460607 -273701
104862 -136807
-803899 -693703
-974 -337735
323678 -209811
-745617 -358684
-984333 603546
722843 -444579
701511 -255784
-676477 -836480
998942 -227888
-502059 -438394
9641...

output:

0.044504743508

result:

ok found '0.04450', expected '0.04450', error '0.00000'

Test #7:

score: 0
Accepted
time: 5ms
memory: 6840kb

input:

1000
4000
703 909
500 496
-214 628
914 -44
-330 -238
-1424 -1426
347 1420
332 -1417
877 1678
-1390 819
-921 525
121 -923
-851 -859
512 -151
765 -109
416 -1529
-269 667
475 -234
-708 300
1917 -1935
-909 1342
1141 -696
-272 1295
1908 -1124
-898 -1225
1608 630
-1937 1246
-255 1021
-1005 -1650
-1595 -39...

output:

0.038185710043

result:

ok found '0.03819', expected '0.03819', error '0.00000'

Test #8:

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

input:

40
3
100 0
0 100
0 0

output:

15.307337294604

result:

ok found '15.30734', expected '15.30734', error '0.00000'

Test #9:

score: 0
Accepted
time: 2ms
memory: 6936kb

input:

48.2842712475
4
-10 -10
10 10
-10 10
10 -10

output:

0.000000059323

result:

ok found '0.00000', expected '0.00000', error '0.00000'