본문 바로가기

Algorithm24

[Baekjoon][20056] 마법사 상어와 파이어볼 출처 - 백준사이트 20056. 마법사 상어와 파이어볼 나의 풀이 해당 문제는 어렵지는 않으며, 몇가지만 고려하면 된다. 맵끼리 이어져 있다는 점. 방향이 모두 짝수이거나 홀수이면 나뉘어지는 파이어볼 방향이 0,2,4,6, 그렇지 않으면 1,3,5,7 위 두사항만 잘 고려한다면 어렵지 않은 문제이다. #include #include #define MAX_SIZE 50 using namespace std; const int dy[] = {-1, -1, 0, 1, 1, 1, 0, -1}; const int dx[] = {0, 1, 1, 1, 0, -1, -1, -1}; typedef struct _FireBall { int dir; int speed; int weight; _FireBall(int dir, .. 2022. 6. 29.
[Baekjoon][20055] 컨베이어 벨트 위의 로봇 출처 - 백준사이트 20055. 컨베이어 벨트 위의 로봇 나의 풀이 해당 문제는 어렵지 않으니, 주석 참고 #include #include using namespace std; int N, K, ret; deque map; bool check_zero() { int cnt = 0; for (int idx = 0 ; idx = K ? true : false; } int main () { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> N >> K; for (int idx = 0 ; idx < 2*N ; idx++) { int input.. 2022. 6. 27.
[Baekjoon][19238] 스타트 택시 출처 - 백준사이트 19238. 스타트 택시 나의 풀이 해당 문제는 어렵지는 않은데 문제에 함정이 있는 걸 조심해야한다. 나는 처음에 풀때, 손님들의 출발지는 모두다 다르고 목적지도 모두다 다르다고 이해하여 문제를 풀었다가, 계속 틀려서, 문제를 자세히 보니까 손님들의 출발지는 모두 다르지만 목적지는 같을 수 있다는 것을 파악했다. 또한, 손님A의 출발지가 손님B의 목적지가 될수도 있다는 사실에 주의하여야 한다. 그래서.. 난.. 코드를 처음부터 다시 짜게 되었다고 한다.... #include #include #include #include #define MAX_SIZE 20 using namespace std; const int dy[] = {-1, 1, 0, 0}; const int dx[] = {0.. 2022. 6. 23.
[Baekjoon][19236] 청소년 상어 출처 - 백준사이트 19236. 청소년 상어 나의 풀이 #include #include using namespace std; const int dy[] = {0, -1, -1, 0, 1, 1, 1, 0, -1}; const int dx[] = {0, 0, -1, -1, -1, 0, 1, 1, 1}; typedef enum State {EMPTY, SHARK, FISH}; typedef struct info { State state; int num; int dir; } Info; Info map[4][4]; int result = 0; void moving_fish(Info (*pmap)[4]) { for (int i=1 ; i 2022. 3. 8.
[Baekjoon][16236] 아기 상어 출처 - 백준사이트 16236. 아기 상어 나의 풀이 이 문제풀때, 머리속에 "아기상어 뚜루루뚜룻~" 노래가 맴도는 순간 집중력 흐트러지니 주의 #include #include #include #define MAX_SIZE 20 using namespace std; typedef struct _shark { int y; int x; } Shark; const int dy[] = {-1, 0, 1, 0}; const int dx[] = {0, -1, 0, 1}; int N; int map[MAX_SIZE][MAX_SIZE]; bool visited[MAX_SIZE][MAX_SIZE] = {false, }; int movingtime, sharkSize, sizeupCnt; int result; Shark .. 2022. 3. 8.
[Baekjoon][14502] 연구소 출처 - 백준사이트 14502. 연구소 나의 풀이 #include #include #include #include #define MAX_SIZE 8 using namespace std; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int N, M, result; int map[MAX_SIZE][MAX_SIZE]; int temp_map[MAX_SIZE][MAX_SIZE]; vector virus; // BFS로 바이러스를 감염시킨다. void BfsVirus() { int after_Wall[MAX_SIZE][MAX_SIZE]; // 벽으로 감싼 후 상황 복사 memcpy(after_Wall, temp_map, sizeof(afte.. 2022. 3. 8.