Algorithm, Data structure/Solved Algorithmic Problem

BAEKJOON 1004 - 어린왕자

JaykayChoi 2016. 7. 12. 23:30

문제: https://www.acmicpc.net/problem/1004


start 와 goal 지점을 둘러싸고 있는 행성의 개수를 구하는 방법으로 풀었습니다. 단, start 와 goal 둘 다 둘러싸고 있는 행성은 제하였습니다.



my solving

c++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;
 
struct Pos
{
    int x, y, r;
};
 
bool whetherAEncloseB(Pos a, Pos b)
{
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) < a.r * a.r;
}
 
int main()
{
    int cases;
    cin >> cases;
 
    for (int i = 0; i < cases; i++)
    {
        Pos start, goal, planet;
        int ret = 0;
        int numPlanet;
        cin >> start.x >> start.y >> goal.x >> goal.y;
        cin >> numPlanet;
        
        for (int j = 0; j < numPlanet; j++)
        {
            cin >> planet.x >> planet.y >> planet.r;
 
            bool isStartEnclosed, isGoalEnclosed;
            isStartEnclosed = whetherAEncloseB(planet, start);
            isGoalEnclosed = whetherAEncloseB(planet, goal);
 
            if (isStartEnclosed == isGoalEnclosed)
                continue;
            if (isStartEnclosed || isGoalEnclosed)
                ret++;
        }
        cout << ret << endl;
    }
 
    return 0;
}
cs


'Algorithm, Data structure > Solved Algorithmic Problem' 카테고리의 다른 글

BAEKJOON 1006 - 습격자 초라기  (0) 2016.07.21
BAEKJOON 1005 - ACM Craft  (0) 2016.07.13
BAEKJOON 1003 - 파보나치 함수  (0) 2016.07.10
BAEKJOON 1002 - 터렛  (0) 2016.07.10
USACO 2.2 - Party Lamps  (0) 2016.07.09