Skip to content

Commit

Permalink
2024-05-14 어린 왕자
Browse files Browse the repository at this point in the history
  • Loading branch information
suhyun113 committed Jul 1, 2024
1 parent a76468a commit c3f2229
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion suhyun113/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
| 4차시 | 2024.04.06 | DP | [피보나치 수 5](https://www.acmicpc.net/problem/10870) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/16) |
| 5차시 | 2024.04.10 | 스택 | [크레인 인형 뽑기 게임](https://school.programmers.co.kr/learn/courses/30/lessons/64061) | [#19](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/19) |
| 6차시 | 2024.04.14 | 스택 | [컨트롤 제트](https://school.programmers.co.kr/learn/courses/30/lessons/120853) | [#21](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/21) |
| 7차시 | 2024.05.09 | 트리 | [원숭이 매달기](https://www.acmicpc.net/problem/2716) | [#31](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/31) |
| 7차시 | 2024.05.09 | 트리 | [원숭이 매달기](https://www.acmicpc.net/problem/2716) | [#31](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/31) |
| 8차시 | 2024.05.14 | 수학 | [어린 왕자](https://www.acmicpc.net/problem/1004) | [#32](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/32) |
42 changes: 42 additions & 0 deletions suhyun113/수학/8-suhyun113.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 1004 : 어린 왕자

#include <iostream>
#include <cmath>
using namespace std;

int main() {
int T; // 테스트 케이스의 개수
int x1, y1, x2, y2; // 출발점, 도착점
int n; // 행성의 개수
int cx, cy, r; // 행성계의 중점과 반지름

cin >> T;
while(T--) {
cin >> x1 >> y1 >> x2 >> y2;
cin >> n;

int enter = 0; // 진입 횟수
int departure = 0; // 이탈 횟수
int count = 0; // 최종 진입/이탈 횟수

while(n--) {
cin >> cx >> cy >> r;
float startDistance = sqrt(pow(cx - x1, 2) + pow(cy - y1, 2)); // 출발점과 원 사이의 거리
float endDistance = sqrt(pow(cx - x2, 2) + pow(cy - y2, 2)); // 도착점과 원 사이의 거리

if (startDistance < r){ // 출발점이 원 내부에 있고,
if (endDistance > r) { // 도착점이 원 외부에 있음
departure++; // 출발점 포함하는 행성 -> 이탈 횟수 증가
}
}
if (startDistance > r) { // 출발점이 원 외부에 있고,
if (endDistance < r) { // 도착점이 원 내부에 있음
enter++; // 도착점 포함하는 행성 -> 진입 회수 증가
}
}
}
count = enter + departure; // 최종 진입/이탈 횟수
cout << count << endl;
}
return 0;
}

0 comments on commit c3f2229

Please sign in to comment.