분류 전체보기

    [C++/백준 21610] 마법사 상어와 비바라기

    //21610 마법사 상어와 비바라기 #include #include #include using namespace std; void solution(vector &basket, vector &dir, int n){ queue cloud; cloud.push({n-1, 0}); cloud.push({n-1, 1}); cloud.push({n-2, 0}); cloud.push({n-2, 1}); // ←, ↖, ↑, ↗, →, ↘, ↓, ↙ int dr[8] = {0, -1, -1, -1, 0, 1, 1, 1};//좌표 이동 int dc[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; for(int i = 0 ; i < dir.size() ; i++) { vector visit(n, vector..

    [C++/백준 19538] 루머

    https://www.acmicpc.net/problem/19538 19538번: 루머 예제 1 0분 : 최초 유포자($1$, $6$번 사람)가 루머를 생성한다. 1분 : $1$번 사람은 $2$, $3$번 사람에게 루머를 퍼뜨린다. $2$번 사람은 주변인 $2$명 중 $1$명이 루머를 믿고 있어 루머를 믿게 된다. $3$ www.acmicpc.net //19538 루머 #include #include #include #include using namespace std; queue q; //주변인, 근원지 queue root; vector t; // 정답 배열 void bfs(vector &adj){ while(!q.empty()) { while(!q.empty()){ int rumor = get(q.fr..

    [C++/백준 2638] 치즈

    //2638 치즈 #include #include #include #include using namespace std; int dr[4] = {0, 0, -1, 1}; int dc[4] = {1, -1, 0, 0}; queue ch; vector paper; bool is_nest(int row, int col, int n, int m){ queue q; vector visit(n, vector(m, false)); q.push({row, col}); visit[row][col] = true; while(!q.empty()){ int r = q.front().first; int c = q.front().second; q.pop(); if(paper[r][c]==1){ //1만나면 막힌것. continue..

    [c++/백준 7569] 토마토

    //7569 토마토(3차 배열.ver) #include #include #include #include using namespace std; //디버깅용 void printArray(int height, int row, int col, vector box){ for(int k = 0 ; k n >> h; vector box(h, vector(n, vector(m, 0))); queue dir; for(int k = 0 ; k < h ; k++){ //높이 for(int i = 0 ; i < n ; i++){ //세로 for..

    [C++/백준 2961] 도영이가 만든 맛있는 음식

    #include #include using namespace std; #define MAX 1000000000 int min_diff = MAX; int n; void permutation(vector visited, vector selected, vector material, int r, int depth){ if(r==depth){ int sum = 0; int product = 1; for (int i = 0; i < r; i++) { product *= selected[i].first; sum += selected[i].second; } min_diff = min(min_diff, abs(product - sum)); return; } for(int i = 0 ; i < n ; i++){ if(!..

    [백준 1713/C++] 후보 추천하기

    Map과 Priority Queue를 이용한 코드이다. //1713 후보 추천하기 #include #include #include #include #include using namespace std; map num; // 번호, {추천받은 순서, 추천수} struct cmp{ bool operator()(int p1, int p2){ if(num[p1].second!=num[p2].second) return num[p1].second > num[p2].second; return num[p1].first > num[p2].first; } }; int main() { int n, total; priority_queue pq; cin >> n >> total; vector recommended(total, 0..