본문 바로가기

Programming

[c++] 백준 - 치킨 배달 (15686번) https://www.acmicpc.net/problem/15686 15686번: 치킨 배달 크기가 N×N인 도시가 있다. 도시는 1×1크기의 칸으로 나누어져 있다. 도시의 각 칸은 빈 칸, 치킨집, 집 중 하나이다. 도시의 칸은 (r, c)와 같은 형태로 나타내고, r행 c열 또는 위에서부터 r번째 칸 www.acmicpc.net DFS의 응용문제로 보이고, vector와 구조체를 활용하면 간단하게 연산이 가능하다. #include #include #include using namespace std; int N, M; int map[51][51]; int minLength = 100000000; typedef struct { int x; int y; int len; }house; vector h; ty.. 더보기
2105. [모의 SW 역량테스트] 디저트 카페 https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5VwAr6APYDFAWu& SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com FIFO를 위한 Queue 의 응용 문제정도로 보인다. 입력에 대한 처리의 수월하게 해 줄 자료구조를 우선적으로 떠올려 보는 습관을 가져야겠다. #include #incluse using namespace std; int N, cnt=-1; int map[21][21]; int visit[21][21]; int dx[] = { 1,1,-1,-1 }; int dy[] = { 1,-1,-1,1 }; .. 더보기
<코드업> 4713 : 공주님의 정원 #include using namespace std; int main() { int n; cin >> n; int **F = new int*[n]; int curr[4]; // start_month, day / end_month, day curr[0] = 3; curr[1] = 1; curr[2] = 11; curr[3] = 30; int tmp[2]; tmp[0] = 0; tmp[1] = 0; for (int i = 0; i > F[i][0] >> F[i][1] >> F[i][2] >> F[i][3]; } int cnt = 0; int flag = 0; while (1) { flag = 0; for (int i = 0; i < n; i++.. 더보기
<코드업> 4684 : 자물쇠 #include using namespace std; int main() { int N; int out_sh1, out_sh2; cin >> N; int* ary = new int[N]; while (1) { for (int i = 0; i > ary[i]; int reverse_cnt = 0; // -1 count for (int i = 0; i < N; i++) { if ((ary[(i + 1) % N] - ary[i] + N) % N == 1) reverse_cnt++; } reverse_cnt = N - reverse_cnt - 1; int reverse_flag = 0; int reverse_end, reverse_start; if (reverse_cnt == -1) .. 더보기
<코드업> 4040 : 펜션 #include #include #include using namespace std; int main() { int n, m; string a; cin >> n >> m; int **schedule = new int*[n]; for (int i = 0; i > a; for (int j = 0; j > s >> t; s--; t -= 2 ; int *cnt_ary = new int[m]; int a1 = s; /// 탐색 시작구간 임시로 a1로 잡음.. 더보기
<코드업> 3321 : 최고의 피자 #include #include using namespace std; int main() { int n,A,B,C; int Total[2]; cin >> n; cin >> A >> B; cin >> C; Total[0] = C;// t_kcal Total[1] = A + B * n;// t_price int *to = new int[n]; for (int i = 0; i > to[i]; Total[0] += to[i]; } sort(to, to + n); int i = 0; while (i (to[i] / B)) { Total[0] -= to[i]; Total[1] -= B; i++; } else break; } cout 더보기
<코드업> 3301 : 거스름돈 #include using namespace std; int main() { int n,tmp = 0 ,cnt=0; cin >> n; if (n >= 50000) { tmp = n / 50000; cnt += tmp; n -= tmp * 50000; tmp = 0; } if (n >= 10000) { tmp = n / 10000; cnt += tmp; n -= tmp * 10000; tmp = 0; } if (n >= 5000) { tmp = n / 5000; cnt += tmp; n -= tmp * 5000; tmp = 0; } if (n >= 1000) { tmp = n / 1000; cnt += tmp; n -= tmp * 1000; tmp = 0; } if (n >= 500) { tmp = n /.. 더보기
<코드업> 3120 : 리모컨 #include using namespace std; int main() { int a, b,cnt=0; cin >> a >> b; a = abs(a - b); while (1) { if (a >= 10 || (a % 10 == 9) || (a % 10 == 8)) { a -= 10; cnt++; a = abs(a); } else break; } while (1) { if (a >= 5 || (a % 5 == 4)) { a -= 5; cnt++; a = abs(a); } else break; } cnt += a; cout 더보기