QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#137504#2350. Integer CowVengeful_Spirit#RE 2ms3648kbC++204.0kb2023-08-10 13:36:172023-08-10 13:36:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 13:36:18]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3648kb
  • [2023-08-10 13:36:17]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const double EPS = 1e-8;
struct Point {
    double x, y;
};
double Dis(const Point &p1, const Point &p2) {
    return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
Point Get(const Point &c, double r, const Point &p) {
    Point u, v;
    if(Dis(p, c) < EPS) return p;
    // cerr << c.x << " " << c.y << " "<< r << "\n";
    // cerr << p.x << " "<< p.y <<"\n";
    // cerr << Dis(p, c) << "\n";
    u.x = c.x + r * fabs(c.x - p.x) / Dis(c, p);
    u.y = c.y + r * fabs(c.y - p.y) / Dis(c, p) * ((c.x - p.x) * (c.y - p.y) < 0 ? -1 : 1);
    v.x = c.x - r * fabs(c.x - p.x) / Dis(c, p);
    v.y = c.y - r * fabs(c.y - p.y) / Dis(c, p) * ((c.x - p.x) * (c.y - p.y) < 0 ? -1 : 1);
    // cerr << u.x << " " << u.y << " " << v.x << " " << v.y << "\n";
    return Dis(u, p) < Dis(v, p) ? u : v;
}

pair<double, double> get(double x, double y, double r2, double X) {
    double delta = r2 - (X - x) * (X - x);
    if(delta < 0) return {0, -1};
    delta = sqrt(delta);
    return {y - delta, y + delta};
}

pair<double, double> in(pair<double, double> x, pair<double, double> y) {
    if(x.first == 0 && x.second == -1) return {0, -1};
    if(y.first == 0 && y.second == -1) return {0, -1};
    if(x.first > y.first) swap(x, y);
    if(y.second <= x.second) return y;
    if(y.first > x.second) return {0, -1};
    return {y.first, x.second};
}

void solve() {
    ll xc, yc, R, x, y;
    cin >> xc >> yc >> R >> x >> y;
    x -= xc, y -= yc;
    if(!x && !y) {
        cout << "0\n" << xc << " " << yc << "\n";
        return ;
    }
    // (0, 0) r, x, y;
    int flg = 0;
    ll ans = 9e18;
    ll sx = 0, sy = 0;
    if(x * x + y * y <= R * R) {
        cout << "0\n" << x + xc << " " << y + yc << "\n";
        return ;
    }
    if(R * R <= 10000) {
        for(ll i = -R; i <= R; ++i) for(int j = -R; j <= R; ++j) {
            if(i * i + j * j <= R * R) {
                if((i - x) * (i - x) + (j - y) * (j - y) <= ans) {
                    ans = (i - x) * (i - x) + (j - y) * (j - y);
                    sx = i, sy = j;
                }
            }
        }
        cout << 1 << "\n" << x + xc << " " << y + yc << " " << sx + xc << " " << sy + yc << "\n";
        return ;
    }
    double dis = sqrt(x * x + y * y) - R;
    // cerr << dis << "\n";
    // return ;
    double mx = (dis + 2) * (dis + 2);
    // cerr << mx << "\n";
    ll L, RR;
    int ff = 0;
    Point st; st.x = x, st.y = y;
    double jx = Get((Point){0, 0}, R, st).x;
    // cerr << jx << "\n";
    ll l = -2e9, r = floor(jx);
    while(l <= r) {
        ll mid = (l + r) >> 1;
        auto[ll, rr] = in(get(0, 0, R * R, mid), get(x, y, mx, mid));
        if(ll == 0 && rr == -1) {
            l = mid + 1;
        }
        else {
            ff = 1;
            // cerr << mid << " " << ll << " "<< rr << "\n";
            L = mid, r = mid - 1;
        }
    }
    assert(ff);
    l = ceil(jx), r = 2e9;
    while(l <= r) {
        ll mid = (l + r) >> 1;
        auto[ll, rr] = in(get(0, 0, R * R, mid), get(x, y, mx, mid));
        if(ll == 0 && rr == -1) r = mid - 1;
        else {
            ff = 1;
            // cerr << "!" << mid << " "<< ll << " " << rr << "\n";
            RR = mid, l = mid + 1;
        }
    }
    // cerr << L << " " << RR << "\n";
    // return ;
    for(ll i = L; i <= RR; ++i) {
        auto[l, r] = in(get(0, 0, R * R, i), get(x, y, mx, i));
        for(ll j = 1ll * l; j <= r; ++j) {
            if((x - i) * (x - i) + (y - j) * (y - j) <= mx) {
                flg = 1;
                mx = (x - i) * (x - i) + (y - j) * (y - j);
                sx = i, sy = j;
            }
        }
    }
    assert(flg);
    cout << 1 << "\n" << x + xc << " " << y + yc << " " << sx + xc << " " << sy + yc << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T; cin >> T;
    for(int o = 1; o <= T; ++o) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 2 1 1 2
3 2 5 -10 3
0 0 1 10 0

output:

0
1 2
1
-10 3 -2 2
1
10 0 1 0

result:

ok correct (3 test cases)

Test #2:

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

input:

1
0 0 1 0 0

output:

0
0 0

result:

ok correct (1 test case)

Test #3:

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

input:

100
-1 0 2 -3 -2
0 -2 2 -2 0
2 -1 1 0 1
-1 -3 1 -1 0
-1 2 2 -1 -1
2 -2 2 0 -3
-2 -3 2 -3 -2
0 1 2 2 1
-1 0 1 -2 -2
2 -2 2 -1 -2
1 2 2 -2 2
-1 2 1 -1 2
-2 1 2 -3 -2
-1 1 1 -1 1
2 2 1 1 -3
2 0 1 -2 -1
-1 2 1 -2 0
2 -2 2 -2 -1
-2 -2 1 1 -2
-1 1 2 2 1
2 -3 1 0 -1
-3 -3 2 2 -1
2 1 1 -1 1
-3 -2 1 -2 -3
0 ...

output:

1
-3 -2 -2 -1
1
-2 0 -1 -1
1
0 1 2 0
1
-1 0 -1 -2
1
-1 -1 -1 0
1
0 -3 1 -3
0
-3 -2
0
2 1
1
-2 -2 -1 -1
1
-1 -2 0 -2
1
-2 2 -1 2
0
-1 2
1
-3 -2 -2 -1
0
-1 1
1
1 -3 2 1
1
-2 -1 1 0
1
-2 0 -1 1
1
-2 -1 0 -2
1
1 -2 -1 -2
1
2 1 1 1
1
0 -1 2 -2
1
2 -1 -1 -3
1
-1 1 1 1
1
-2 -3 -2 -2
0
-2 -2
0
-2 -2
0
1 -1
...

result:

ok correct (100 test cases)

Test #4:

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

input:

100
-5 9 1 -2 -7
3 1 6 9 2
-2 -1 2 -7 3
-10 -8 7 -8 6
0 3 9 -6 -7
6 4 9 -1 4
8 6 7 -7 7
3 -7 7 2 0
-5 -1 6 -7 -7
-5 8 7 -9 -6
-6 -5 5 -10 -9
-7 1 9 7 -2
-4 9 4 8 3
3 -9 6 2 -2
-1 -7 3 -8 2
-2 -5 4 -1 0
1 2 9 -5 5
0 9 5 -4 -1
-10 8 2 -3 -7
-8 -3 3 2 -3
3 3 7 -4 6
6 0 6 -3 5
-7 5 9 9 9
2 0 2 8 -10
2 1...

output:

1
-2 -7 -5 8
1
9 2 9 1
1
-7 3 -3 0
1
-8 6 -10 -1
1
-6 -7 -4 -5
0
-1 4
1
-7 7 1 6
1
2 0 3 0
1
-7 -7 -7 -6
1
-9 -6 -5 1
1
-10 -9 -9 -9
1
7 -2 2 1
1
8 3 -1 7
1
2 -2 3 -3
1
-8 2 -3 -5
1
-1 0 -2 -1
0
-5 5
1
-4 -1 -3 5
1
-3 -7 -10 6
1
2 -3 -5 -3
1
-4 6 -3 6
1
-3 5 1 3
1
9 9 1 9
1
8 -10 2 -2
1
7 -1 5 1
0
2...

result:

ok correct (100 test cases)

Test #5:

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

input:

100
-52 -13 72 44 58
79 -58 32 60 11
-50 21 75 95 65
-37 -61 21 -74 -40
0 -88 14 11 -49
10 -80 46 79 -17
75 -94 90 61 -34
-80 19 85 -7 -20
-72 42 56 67 -89
21 51 39 20 88
82 32 56 88 -82
3 51 31 -45 -53
50 12 91 9 46
-45 29 25 76 27
-19 -14 81 22 97
5 93 35 98 64
54 90 88 -100 63
-60 -18 81 -20 8
34...

output:

1
44 58 7 28
1
60 11 68 -28
1
95 65 22 42
1
-74 -40 -54 -49
1
11 -49 5 -75
1
79 -17 43 -48
0
61 -34
0
-7 -20
1
67 -89 -30 5
0
20 88
1
88 -82 82 -24
1
-45 -53 -10 23
0
9 46
1
76 27 -20 29
1
22 97 9 62
1
98 64 39 85
1
-100 63 -33 77
0
-20 8
1
62 16 46 51
1
-46 66 -79 -27
1
62 -91 -11 -54
1
-55 -54 73 ...

result:

ok correct (100 test cases)

Test #6:

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

input:

100
-14 48 115 -133 160
80 40 30 181 139
114 -109 102 -111 -14
-51 175 113 40 -116
-44 -171 69 6 -128
18 -23 159 94 170
-150 71 199 -167 -181
82 173 50 -138 41
-27 -126 119 195 134
-129 16 169 -103 51
183 136 117 -196 54
25 61 27 166 12
-156 63 199 -8 -56
-143 138 31 -137 125
48 16 44 -83 37
150 -16...

output:

1
-133 160 -98 126
1
181 139 102 60
1
-111 -14 19 -72
1
40 -116 -18 67
0
6 -128
1
94 170 76 125
1
-167 -181 -167 -127
1
-138 41 40 146
1
195 134 53 -38
0
-103 51
1
-196 54 69 110
1
166 12 50 51
0
-8 -56
0
-137 125
1
-83 37 5 25
1
-71 -195 9 -183
1
-77 -188 -51 120
1
-88 135 -100 -179
0
170 90
1
-25 ...

result:

ok correct (100 test cases)

Test #7:

score: -100
Dangerous Syscalls

input:

100
30 194 241 273 -11
476 -181 37 -18 -139
-162 496 295 113 250
-413 467 26 -100 312
-322 -120 423 -86 222
464 231 266 -421 497
249 -467 327 -183 -486
-316 486 468 -295 -286
92 141 487 -146 -13
108 -300 14 318 17
229 -180 49 -247 -464
-385 326 56 -493 62
-365 349 114 -258 293
44 -443 26 -139 -313
6...

output:


result: