step 1
더보기


맥스를 반지름이 0.5인 원으로 생각하면 조금 복잡합니다. 사람을 점으로 표현할 수 있는 방법이 없을까요?
맥스의 중심을 기준으로 자동차의 빨간 원 안에 들어가면 차와 충돌하게 됩니다.

차 부분만 확대하면 다음과 같습니다.0.5만큼 살찌웠다고 생각하면 됩니다.

그럼 맥스에 해당하는 점이 자동차 주위 빨간 영역과 겹치는지 확인하면 됩니다.
step 2
더보기


지금부터 자동차를 고정시킬 것입니다.
맥스는 위로 M의 속도로, 차는 오른쪽으로 B의 속도로 달립니다.
그럼 이건 차가 고정되어 있고 맥스가 위로 M, 왼쪽으로 B의 속도로 달리는 것과 같습니다.

맥스는 t초 뒤에 출발합니다. 그 말은 맥스가 처음 위치에서 Bt미터 왼쪽에서 출발한다는 것과 같습니다.

그럼 자동차 입장에서 맥스가 어떻게 움직이는지 구할 수 있습니다. 맥스의 경로와 자동차의 영역이 겹치는지 아닌지를 보면 쉽게 해결할 수 있습니다.
코드
더보기
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
double m, b, d, t;
int ttt,i;
scanf("%d", &ttt);
while (ttt--) {
scanf("%lf%lf%lf%lf", &m, &b, &d, &t);
for (i = 0;i < 10;i++) {
double cd = abs((m * (-d - 4 * i) / b + 5 + m * t + 0.5)) / (sqrt(m * m / (b * b) + 1));
if (cd <= 0.5) { printf("Collision with bicycle %d\n", i + 1); break; }
cd = abs((m * (-d - 4 * i - 2) / b + 5 + m * t + 0.5)) / (sqrt(m * m / (b * b) + 1));
if (cd <= 0.5) { printf("Collision with bicycle %d\n", i + 1); break; }
double bd1 = (5 + m * t) * (-b / m);
double bd2 = (6 + m * t) * (-b / m);
if (bd1 > -d - 4 * i && bd2 > -d - 4 * i) {
if (i == 0) printf("Max beats the first bicycle\n");
else printf("Max crosses safely after bicycle %d\n",i);
break;
}
else if (bd1 < -d - 4 * i - 2 && bd2 < -d - 4 * i - 2) {
if (i == 9) {
printf("Max crosses safely after bicycle %d\n", 10);
}
}
else {
printf("Collision with bicycle %d\n", i + 1);
break;
}
}
}
return 0;
}
'PS - 알고리즘' 카테고리의 다른 글
23755 - 카드컨트롤 (Hard) (0) | 2024.10.07 |
---|---|
24520 - Meet In The Middle (0) | 2024.09.30 |
1314 - 동굴 탐험 (0) | 2024.09.16 |
31725 - 포닉스와 달구 (0) | 2024.09.09 |
2969 - 메뚜기 (0) | 2024.09.02 |