Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 백준 5397
- heap
- ㅣ풀이
- 해시 구현
- 해시구현
- 백준 2447
- C/C++ 구현
- 구현
- 별 찍기 10
- c#
- qorwns
- 자료구조
- Stack 이란
- 풀이
- AVL 시간 복잡도
- 1764
- 백준 17822
- 백준
- 백준 1158
- 게리멘더링2
- 시간 복잡도
- 조세퍼스 순열
- 5397
- 백준 17471
- 스택의 특징
- 백준 1406
- dfs
- 원판 돌리기
- 버킷 정렬
- 백준 17779
Archives
- Today
- Total
홍시홍의 프로그래밍
[백준 14890] 경사로 본문
https://www.acmicpc.net/problem/14890
14890번: 경사로
첫째 줄에 N (2 ≤ N ≤ 100)과 L (1 ≤ L ≤ N)이 주어진다. 둘째 줄부터 N개의 줄에 지도가 주어진다. 각 칸의 높이는 10보다 작거나 같은 자연수이다.
www.acmicpc.net
요구사항
지나다닐 수 있는 길의 수 구하기
시뮬레이션
예외처리 잘해주기
#include <iostream>
#include <deque>
#include <string.h>
#include <algorithm>
#pragma warning(disable:4996)
using namespace std;
int map[101][101];
int visit[101];
int n, l;
int ans = 0;
void garo(int r)
{
int c = 0;
while (true)
{
if (c == n - 1)
{
ans++;
break;
}
if (map[r][c] == map[r][c + 1])
{
c++;
continue;
}
else if (abs(map[r][c] - map[r][c + 1]) > 1)
break;
//현재가 클때
else if (map[r][c] - map[r][c + 1] == 1)
{
if (c + l >= n)
return;
int a = map[r][c + 1];
for (int i = c + 1; i <= c + l; i++)
{
if (visit[i] == 1)
return;
if (a == map[r][i])
{
visit[i] = 1;
continue;
}
else
return;
}
c = c + l;
continue;
}
//현재가 작을때
else if (map[r][c] - map[r][c + 1] == -1)
{
if (c - l + 1 < 0)
return;
for (int i = c; i >= c - l + 1; i--)
{
if (visit[i] == 1)
return;
if (map[r][c] == map[r][i])
{
visit[i] = 1;
continue;
}
else
return;
visit[i] = 1;
}
c++;
continue;
}
}
}
void sero(int c)
{
int r = 0;
while (true)
{
if (r == n - 1)
{
ans++;
break;
}
if (map[r][c] == map[r + 1][c])
{
r++;
continue;
}
else if (abs(map[r][c] - map[r + 1][c]) > 1)
break;
//현재가 클때
else if (map[r][c] - map[r + 1][c] == 1)
{
if (r + l >= n)
return;
int a = map[r + 1][c];
for (int i = r + 1; i <= r + l; i++)
{
if (visit[i] == 1)
return;
if (a == map[i][c])
{
visit[i] = 1;
continue;
}
else
return;
}
r = r + l;
continue;
}
//현재가 작을때
else if (map[r][c] - map[r + 1][c] == -1)
{
if (r + 1 - l < 0)
return;
for (int i = r; i >= r - l + 1; i--)
{
if (visit[i] == 1)
return;
if (map[r][c] == map[i][c])
{
visit[i] = 1;
continue;
}
else
return;
visit[i] = 1;
}
r++;
continue;
}
}
}
int main()
{
scanf("%d%d", &n, &l);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
scanf("%d", &map[i][j]);
}
}
for (int i = 0; i < n; i++)
{
memset(visit, 0, sizeof(visit));
garo(i);
memset(visit, 0, sizeof(visit));
sero(i);
}
cout << ans << endl;
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 1936] 소수 경로 (0) | 2020.02.13 |
---|---|
[백준 16234] 인구 이동 (0) | 2020.02.08 |
[백준 14889] 스타트와 링크 (0) | 2020.02.08 |
[백준 16235] 나무 재테크 (0) | 2020.02.08 |
[백준 17144] 미세먼지 안녕 (0) | 2020.02.04 |
Comments