Algorithm 14

[프로그래머스] 코딩테스트 고득점 Kit 완전탐색 C++ (최소직사각형, 모의고사)

1️⃣ 최소직사각형 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드#include #include #include using namespace std;vector v1;vector v2;int solution(vector> sizes) { int answer = 0; for (int i=0;i= sizes[i][1]){ v1.push_back(sizes[i][0]); v2.push_back(sizes[i][1]); } else { v1.push_back(sizes[i][1]); v2.pu..

Algorithm 2024.11.19

[프로그래머스] 코딩테스트 고득점 Kit 힙 C++ (더 맵게, 디스크 컨트롤러, 이중우선순위큐)

1️⃣ 더 맵게 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr생각 흐름일단 내림차순 정렬을 해서 pop_back을 사용하자 (vector 사용)pre, now를 선언하고,pre가 K보다 작으면 now랑 섞기코드1 - 오답#include #include #include #include using namespace std;bool compare(int a, int b){ return a > b;}int solution(vector scoville, int K) { int answer = 0; sort(scoville.begin(), scoville.end(), compare); ..

Algorithm 2024.10.26

[프로그래머스] 코딩테스트 고득점 Kit 정렬 C++ (K번째 수, 가장 큰 수, H-Index)

1️⃣ K번째수 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 생각 흐름인덱스만큼만 새로운 벡터에 저장하고 sort하고 k번째 수 찾아서 answer에 넣기코드// 241024 23:50 시작 11:59 끝#include #include #include #include using namespace std;vector solution(vector array, vector> commands) { vector answer; for (auto command: commands){ vector v; for (int i=command[0]-1;i vector v를 갱신해주..

Algorithm 2024.10.25

[프로그래머스] 코딩테스트 고득점 Kit 해시 C++ (폰켓몬, 완주하지 못한 선수, 전화번호 목록, 의상, 베스트앨범)

1️⃣ 폰켓폰 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드// 241023 16:20 시작// 241023 16:30 끝#include #include using namespace std;set s;int solution(vector nums) { int answer = 0; for (int num: nums) s.insert(num); if (s.size() > (nums.size()/2)) answer = nums.size()/2; else answer = s.size(); return answer;}생각 흐름문제를 읽으면서 '오?! ..

Algorithm 2024.10.24

[프로그래머스 level3] 파괴되지 않은 건물 C++

프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 규칙내구도를 가진 건물이 각 칸마다 하나씩 존재적은 건물을 공격해 파괴 - 적의 공격을 받으면 내구도 감소내구도가 0 이하면 차괴아군은 회복 스킬을 사용해 내구도 높일 수 있음(row, column) 형태파괴되었다가 복구 가능데이터내구도 board 배열적의 공격 혹은 아군의 회복 스킬 skill 배열skill은 [type, r1,c1,r2,c2,degree]type: 적1 or 아군2degree: 내구도 혹은 회복력출력: 적의 공격과 아군의 회복 스킬이 모두 끝났을 때 파괴되지 않은 건물의 수 리턴  풀이#inc..

Algorithm 2024.10.08

[프로그래머스 level3] 이중우선순위큐 C++

프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 문제: 우선순위큐에 저장되어 있는 연산 명령어를 이용해 우선순위큐 데이터 추가 및 삭제입력: 연산 명령어가 저장되어 있는 operations 배열출력: [max, min] 풀이1️⃣ - 오답#include #include #include #include using namespace std;int cnt=0;vector solution(vector operations) { vector answer; priority_queue , less> max_pq; priority_queue , greater>..

Algorithm 2024.10.08

[프로그래머스 level2] 파일명 정렬 C++

프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 입력1000개 이하의 파일명이 있는 files출력규칙에 따라 파일명이 올바르게 정렬된 배열규칙head: 알파벳 순 (대소문자 구분 x)number: 9 tail: files 배열에서 먼저 나오는 순서로 정렬풀이 방법head, number, tail 찾기 -> 문자열에서 숫자가 나오는 인덱스 체크구조체를 사용해 파일명을 head, number, idx로 나누어 저장head, number, 원래 파일 순서로 정렬 (tail은 정렬에 사용되지 x)풀이#include #include #include using names..

Algorithm 2024.10.05

[백준 BOJ] 2473 세 용액 C++

2470 두 용액 문제의 응용이다.  입력첫째줄: 전체 용액의 수 N (3 둘째줄: 용액의 특성값 (-10^9 ~ 10^9)출력특성값을 0에 가깝게 만드는 세 용액의 특성값 출력 (오름차순으로)풀이1️⃣ - 시간초과#include #include #include #include #define INF 987654321using namespace std;int N;vector v;vector answer;int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> N; int a; for (int i=0;i> a; v.push_back(a); } sort(v.begin(), v.end()); in..

Algorithm 2024.10.03

백트래킹

1. 프로그래머스 2022 Kakao Blind Recruitment 양궁대회  프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr풀이1️⃣ - 오답// 라이언 b vs 어피치 a// 규칙: a>=b면 어피치가 k점, a 2^11의 경우가 존재#include #include using namespace std;int arr[11];int max_diff = 0;vector ryan(11, 0);vector apeach;vector answer = { -1 };int cmp(vector ryan, vector apeach) { int ryan_score = 0..

Algorithm 2024.10.01

[프로그래머스 level1] 개인정보 수집 유효기간 C++

프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 풀이 1️⃣ - 오답// 입력: 약관 종류 arr[i] | 약관 유효기간 terms[i]// 입력: 번호 n | 오늘 날짜 today | 약관 종류 string -> 개인정보수집날짜+약관종류 privacies[i] // 출력: 파기해야하는 개인정보의 번호#include #include #include using namespace std;vector solution(string today, vector terms, vector privacies) { vector answer; // today: 2..

Algorithm 2024.10.01