목록Problem Solving (223)
Life Engineering
https://programmers.co.kr/learn/courses/30/lessons/42842?language=cpp 코딩테스트 연습 - 카펫 Leo는 카펫을 사러 갔다가 아래 그림과 같이 중앙에는 노란색으로 칠해져 있고 테두리 1줄은 갈색으로 칠해져 있는 격자 모양 카펫을 봤습니다. Leo는 집으로 돌아와서 아까 본 카펫의 노란색과 programmers.co.kr #include #include using namespace std; vector solution(int brown, int yellow) { vector answer; int sero=1; int garo=((brown+4)/2)-sero; while (garo>=sero){ if (garo*sero==brown+yellow){ an..
https://programmers.co.kr/learn/courses/30/lessons/42578 from collections import defaultdict def solution(clothes): answer = 1 clothing=defaultdict(int) for name, kind in clothes: clothing[kind]+=1 for kind in clothing: answer*=(clothing[kind]+1); return answer-1; 처음엔 옷 종류 조합을 구해서 각 옷 종류 별 수를 곱해주려다가, 조합을 사용하니 1번 테케에서 시간초과가 발생했다. 그래서 조합을 사용하지 않고, (옷 종류 별 옷 수+1) 를 옷 종류 별로 다 곱해준다. +1 해준것은 해당 옷 종류를 ..
https://www.acmicpc.net/problem/19236https://www.acmicpc.net/problem/19236 19236번: 청소년 상어 첫째 줄부터 4개의 줄에 각 칸의 들어있는 물고기의 정보가 1번 행부터 순서대로 주어진다. 물고기의 정보는 두 정수 ai, bi로 이루어져 있고, ai는 물고기의 번호, bi는 방향을 의미한다. 방향 bi는 www.acmicpc.net #include #include #include #include using namespace std; int dx[8] = { -1,-1,0,1,1,1,0,-1 }; int dy[8] = { 0,-1,-1,-1,0,1,1,1 }; struct fish { int num; int pos; }; struct info ..
https://www.acmicpc.net/problem/21608 21608번: 상어 초등학교 상어 초등학교에는 교실이 하나 있고, 교실은 N×N 크기의 격자로 나타낼 수 있다. 학교에 다니는 학생의 수는 N2명이다. 오늘은 모든 학생의 자리를 정하는 날이다. 학생은 1번부터 N2번까지 번호 www.acmicpc.net #include #include #include #include #include using namespace std; int dx[4] = { -1,1,0,0 }; int dy[4] = { 0,0,-1,1 }; int classroom[21][21] = { 0, }; struct info { int like, vacant, row, col; bool operator b.col;//열 오..