목록Problem Solving (223)
Life Engineering
https://programmers.co.kr/learn/courses/30/lessons/12985 코딩테스트 연습 - 예상 대진표 △△ 게임대회가 개최되었습니다. 이 대회는 N명이 참가하고, 토너먼트 형식으로 진행됩니다. N명의 참가자는 각각 1부터 N번을 차례대로 배정받습니다. 그리고, 1번↔2번, 3번↔4번, ... , N-1번↔N programmers.co.kr #include using namespace std; int numbering(int n){ if (n%2==0) return n/2; else return (n+1)/2; } int solution(int n, int a, int b) { int answer = 0; while (a!=b){ a=numbering(a); b=number..
https://programmers.co.kr/learn/courses/30/lessons/12953 코딩테스트 연습 - N개의 최소공배수 두 수의 최소공배수(Least Common Multiple)란 입력된 두 수의 배수 중 공통이 되는 가장 작은 숫자를 의미합니다. 예를 들어 2와 7의 최소공배수는 14가 됩니다. 정의를 확장해서, n개의 수의 최소공배 programmers.co.kr #include #include #include using namespace std; int gcd(int a, int b){ int a1=max(a,b); int b1=min(a,b); while (b1){ int c=a1%b1; a1=b1; b1=c; } return a1; } int lcm(int g, int a,..
https://programmers.co.kr/learn/courses/30/lessons/49191 코딩테스트 연습 - 순위 5 [[4, 3], [4, 2], [3, 2], [1, 2], [2, 5]] 2 programmers.co.kr #include #include #include using namespace std; bool floyd[101][101]={false,}; int solution(int n, vector results) { int answer = 0; for (auto r : results) floyd[r[0]][r[1]]=true; for (int k=1; k
https://programmers.co.kr/learn/courses/30/lessons/72412 >target; int cnt=lower_bound(m[q].begin(), m[q].end(), target)-m[q].begin(); answer.push_back(m[q].size()-cnt); } return answer; } map을 이용해서 풀었다. 그리고 점수를 탐색할 때 미리 정렬해줘서 이분탐색하여 효율성을 높이는게 중요하다. 해당 info에서 나올 수 있는 모든 경우의 수를 map의 key에 넣어주고, value는 점수를 넣어준다. 예를 들어, "java backend junior pizza 100" 이라면, 2^4=16가지의 경우를 map의 키로 삼고, value를 100으로 하는 것이..