A. Race time limit per test2 seconds memory limit ...
Creado el: 23 de junio de 2025
Respondido usando O4 Mini High por Chat01
Creado el: 23 de junio de 2025
Respondido usando O4 Mini High por Chat01
A. Race
time limit per test2 seconds
memory limit per test256 megabytes
Alice and Bob participate in a game TV show. When the game starts, the prize will be dropped to a certain point, and whoever gets to it first will get the prize.
Alice decided that she would start running from point a
. Bob, however, has not yet chosen his starting position.
Bob knows that the prize could drop either at point x
or at point y
. He also knows that he can reach the prize faster than Alice if the distance from his starting position to the prize is strictly less than the distance from Alice's starting position to the prize. The distance between any two points c
and d
is calculated as |c−d|
.
Your task is to determine whether Bob can choose an integer point that is guarantee to get to the prize faster, regardless of where it appears (at point x
or y
). Bob can choose any integer point, except for a
(in particular, he can choose to start in point x
, point y
, or any other point, but not a
).
Input
The first line contains a single integer t
(1≤t≤1000
) — the number of test cases.
The only line of each test case contains three integers a
, x
, y
(1≤a,x,y≤100
). Points a
, x
, and y
are pairwise distinct.
Output
For each test case, print "YES" (case insensitive) if Bob can choose an integer point that is guarantee to get to the prize faster, regardless of where it appears. Otherwise, print "NO" (case insensitive).
Example
InputCopy
3
1 3 4
5 3 1
3 1 5
OutputCopy
YES
YES
NO
Note
In the first example, Bob can choose point 4
. If the prize will be at point x
, then Bob's distance is |4−3|=1
and Alice's distance is |1−3|=2
. If the prize will be at point y
, then Bob's distance is |4−4|=0
and Alice's distance is |1−4|=3
.
In the second example, Bob can choose point 2
. If the prize will be at point x
, then Bob's distance is |2−3|=1
and Alice's distance is |5−3|=2
. If the prize will be at point y
, then Bob's distance is |2−1|=1
and Alice's distance is |5−1|=4
.
In the third example, Bob cannot choose a point to guarantee his victory.
c++ code
fix this code
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int p, m, n;
cin >> p >> m >> n;
textint d1 = abs(p - m); int d2 = abs(p - n); int d = abs(m - n); int mn = d1 < d2 ? d1 : d2; cout << (d < 2 * mn ? "YES" : "NO") << endl; } return 0;
}
The mistake is that Bob’s “winning” starting positions form the intersection of two intervals:
textI₁ = { b : |b−x| < |a−x| } ⇔ x−D₁+1 ≤ b ≤ x+D₁−1 I₂ = { b : |b−y| < |a−y| } ⇔ y−D₂+1 ≤ b ≤ y+D₂−1
where D₁=|a−x| and D₂=|a−y|. That intersection is non‐empty exactly when
|x−y| ≤ D₁ + D₂ − 2.
Below is a corrected C++ implementation:
cpp#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int a, x, y; cin >> a >> x >> y; int D1 = abs(a - x); int D2 = abs(a - y); int distXY = abs(x - y); // Intersection non-empty ⇔ distXY <= D1 + D2 - 2 if (distXY <= D1 + D2 - 2) { cout << "YES\n"; } else { cout << "NO\n"; } } return 0; }
Explanation:
a
and the prize be at either x
or y
.b
such that|b−x| < |a−x|
and|b−y| < |a−y|
.2·D₁−1
and 2·D₂−1
around x
and y
respectively.text|x−y| ≤ (D₁−1) + (D₂−1) = D₁ + D₂ − 2.
b
≠ a
, so Bob can pick one and always beat Alice.