TopCoder

qwe1rt1yuio
所以 45 跟 60 分差在哪

User's AC Ratio

88.2% (15/17)

Submission's AC Ratio

53.6% (30/56)

Tags

Description

給定平面上從原點射出去的兩個射線,分別從 $(0, 0)$ 射向點 $p$、$(0, 0)$ 射向點 $q$,求以原點為中心、半徑 $r$ 的圓與這兩條射線交點的距離。

以下為提供的解法,但是卻得到 WA,請在 edit distance

  • $3$ (easy, 25 分)
  • $2$ (mid, 25 分)
  • $1$ (hard, 50 分)

以內將該程式碼修改正確:

Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define X first
#define Y second

typedef pair<double, double> pdd;
pll operator+(const pll &a, const pll &b)
{ return pll(a.X + b.X, a.Y + b.Y); }
pll operator-(const pll &a, const pll &b)
{ return pll(a.X - b.X, a.Y - b.Y); }
pll operator*(const pll &a, ll b)
{ return pll(a.X * b, a.Y * b); }
pll operator/(const pll &a, ll b)
{ return pll(a.X / b, a.Y / b); }
pdd operator/(const pll &a, double b)
{ return pdd(a.X / b, a.Y / b); }
pdd operator-(const pdd &a, const pdd &b)
{ return pdd(a.X - b.X, a.Y - b.Y); }
ll dot(const pll &a, const pll &b)
{ return a.X * b.X + a.Y * b.Y; }
ll cross(const pll &a, const pll &b)
{ return a.X * b.Y - a.Y * b.X; }
double abs(const pll &a)
{ return sqrt(dot(a, a)); }
double abs(const pdd &a)
{ return sqrt(dot(a, a)); }

double dot(pdd &a, pdd &b) {
    return a.X * b.X + a.Y * b.Y;
}
double abs(pdd &a) {
    return sqrt(dot(a, a));
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    pll p, q;
    int r;
    cin >> p.X >> p.Y >> q.X >> q.Y >> r;
    cout << fixed << setprecision(10) << abs((p / (abs(p) / r)) - (q / (abs(q) / r))) << "\n";
}

Input Format

輸入只有一行,此行輸入五個整數 $p_x, p_y, q_x, q_y, r$。

  • $0\leq p_x, p_y, q_x, q_y \leq 100$
  • $(p_x, p_y) \neq (0, 0)$
  • $(q_x, q_y) \neq (0, 0)$
  • $(p_x, p_y) \neq (q_x, q_y)$
  • $1\leq r\leq 100$

Output Format

輸出一浮點數,代表兩個交點的距離。

只要你輸出的答案滿足相對或絕對誤差不超過 $10^ {-6}$ 皆視為正確。更嚴謹地說,假設 $a$ 是正確答案且 $b$ 是你的答案,如果符合 $\frac{|a-b|}{\max(|a|, |b|, 1)}\le 10^ {-6}$ 就會視為正確。

Sample Input 1

4 0 0 5 2

Sample Output 1

2.8284271247

Hints

Problem Source

Subtasks

No. Testdata Range Constraints Score
1 0 範例測資。 0
2 0~10 無特別限制。 100

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 1048576 65536 1 2
1 1000 1048576 65536 2
2 1000 1048576 65536 2
3 1000 1048576 65536 2
4 1000 1048576 65536 2
5 1000 1048576 65536 2
6 1000 1048576 65536 2
7 1000 1048576 65536 2
8 1000 1048576 65536 2
9 1000 1048576 65536 2
10 1000 1048576 65536 2