반응형

Programming/Baekjoon 117

백준 1916 최소비용구하기 [c++]

#include #include #include #include #include using namespace std; //백준 1916 - 다익스트라 int n, m;//도시의개수, 버스의개수 int map[1001][1001];//이동 비용 저장 vectorv(1001); int start, des;//출발도시, 도착도시 int t1, t2, t3; int answer = 987654321;//결과 bool visited[1001][1001];//방문확인할 배열 typedef struct { int x;//현재도시위치 int num;//비용 }node; struct cmp { bool operator()(node n1, node n2) { return n1.num > n2.num;//작은값이 top을 ..

백준 14891 톱니바퀴 [c++]

#include #include #include #include using namespace std; //톱니바퀴는 총4개, 입력할때 12방향부터 시계방향으로 입력 //N극은 0 , S극은 1 //같은 극이면 회전 X, 다른극일경우 이전 톱니바퀴에 반대방향으로 회전 ex) 이전바퀴 시계방향회전 -> 다음 바퀴 반시계방향회전 int k;//회전회수 int num;//회전할 톱니 번호 int dir;//회전방향, 1일경우 시계방향 -1일 경우 반시계방향 int t1[8], t2[8], t3[8], t4[8];//톱니바퀴 string str; int answer = 0;//결과값 void func(int idx)//매개변수로 회전해야할 톱니바퀴 번호를 받고 시계방향으로 회전하는 함수 { int temp; in..

백준 10026 적록색약 [c++]

#include #include #include #include using namespace std; //R빨 G초 B파 //적록색약은 R G 똑같이 int n; char map[101][101]; bool visited[101][101]; int dx[4] = { 1,0,-1,0 }; int dy[4] = { 0,1,0,-1 }; int answer=0; int answer2=0; void func(int x, int y, char color, bool check)//첫번째 매개변수 부터 x,y좌표, 현재구역의색, 적록색약의 여부 { queueq; q.push({ x,y }); visited[x][y] = true; while (!q.empty()) { int qx = q.front().first; i..

백준 7562 나이트의이동 [c++]

#include #include #include #include using namespace std; int t;//테스트 케이스 개수 int n;//한변의 길이 int nx, ny;//나이트의 위치 int rx, ry;//목적지의 위치 int map[301][301]; bool visited[301][301]; vectorv; int dx[8] = { 2,1,-1,-2,-2,-1,1,2 }; int dy[8] = { 1,2,2,1,-1,-2,-2,-1 }; typedef struct { int tx; int ty; int tcnt; }node; int func(int x, int y) { queueq; q.push({ x,y,0 }); visited[x][y] = true; while (!q.empty..

백준 1931 회의실 배정 [c++]

#include #include #include using namespace std; int n;//회의의 수 int t1, t2; int result = 1;//회의의최대개수 첫번째경우 int result2 = 1;//회의의최대개수 두번째경우 vectorv;//회의시작 종료시간 저장할 vector bool cmp(pair p1, pairp2)//비교함수, 회의의 시작시간을 기준으로 오름차순정렬, 같은 경우 종료시간 비교 { if (p1.first == p2.second) return p1.second < p2.second; else return p1.first < p2.first; } bool cmp2(pair p1, pairp2)//회의의 종료시간 기준으로 오름차순 정렬 { if (p1.second ..

백준 2583 영역구하기 [c++]

#include #include #include #include #include #include #include using namespace std; int map[101][101]; bool visited[101][101]; int m, n, k;//세로,가로,직사각형 개수 vectorv; int answer = 0; int dx[4] = { 1,0,-1,0 }; int dy[4] = { 0,1,0,-1 }; int check = 2; int t1, t2, t3, t4;//왼쪽아래 xy, 오른쪽위 xy //ex 왼쪽(0,2) , 오른쪽(4,4) -> 0,2 - 0,3 - 1,2 -1,3 - 2,2 - 2,3 - 3,2 - 3,3 typedef struct { int tx; int ty; }node; v..

백준 11286 절댓값 힙 [c++]

#include #include #include #include #include #include #include using namespace std; struct cmp { bool operator()(int a, int b) { if (abs(a) == abs(b))//절대값이 같은경우 더 작은 값을 후순위로 저장 return a > b; else return abs(a) > abs(b);//절대값이 더작은 값 후순위로 저장 } }; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; priority_queuepq; int temp; vectorv; cin >> n; for (int i = 0; i < n; i+..

백준 1012 유기농배추 [c++]

#include #include #include #include #include #include #include using namespace std; int map[51][51]; bool visited[51][51]; int t;//테스트케이스 개수 int m, n, k;//가로, 세로, 배추위치개수 int x, y; int dx[4] = { 1,0,-1,0 };//상,하,좌,우 탐색 int dy[4] = { 0,1,0,-1 }; vectoranswer; void bfs(int stx, int sty) { queueque; que.push({ stx,sty }); visited[stx][sty] = true; while (!que.empty()) { int qx = que.front().first; i..

반응형