본문 바로가기

분류 전체보기145

랜선 자르기 #1654 c++ 풀이 https://www.acmicpc.net/problem/1654 처음 생각한것 : 순회 2억번 이상 연산으로, 시간 초과가 날 가능성이 있어보여서 순회가 아닌 다른 방식을 사용해야한다. 랜선을 자를 수 있는 경우가 1~들어온 랜선의 최대길이 이므로, sorting되어진 리스트의 이진 탐색을 사용하여, 구현해야하는 문제이다. 또한 자료형도 생각해봐야한다. 정수 끝까지 2^31-1 값이 들어갈 수 있으므로, unsigned int를 사용해주는 것이 좋다. #include #include #include using namespace std; unsigned int list[10000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.t.. 2023. 10. 6.
[STL] vector unique 함수 vector 배열에서 중복되지 않는 원소들을 앞에서부터 채워나가는 함수이다. algorithm이라는 헤더에 존재하는 함수이다. unique함수를 사용하면 중복 없는 요소를 채운 후 남은 요소는 원래 배열의 요소를 그대로 넣는다. 즉, 중복되지 않는 원소들을 앞에서부터 채워나가는 역할을 하기때문에 남은 뒷부분은 그대로 vector 원소값이 존재한다. 또한 unique 함수가 끝나면 중복이 없는 요소의 끝 점을 반환한다. 중복을 완전히 제거하지 못하는 문제를 해결하기 위해 erase 함수를 사용해서 남은 뒷부분을 제거야한다. erase 함수는 vector 배열에서 특정 원소를 삭제하는 함수이다. v.erase(v.begin(), v.end()) 명령어를 입력하면 처음부터 끝까지 배열 내 모든 원소가 제거된다.. 2023. 10. 5.
수 찾기 #1920 c++ 풀이 #include #include #include #include #include #include using namespace std; vector arr1; vector arr2; int main() { int N, M; ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int temp; cin >> N; for (int i = 0; i > temp; arr1.push_back(temp); } cin >> M; for (int i = 0; i > temp; arr2.push_back(temp); } sort(arr1.begin(), arr1.end()); for (int i = .. 2023. 10. 5.
스택수열 #1874 c++ 풀이 #include #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; stack s; cin >> n; int temp; int topValue = 0; string answer; while (n--) { cin >> temp; if (temp > topValue) { while (temp > topValue) { s.push(++topValue); answer += '+'; } s.pop(); answer += '-'; } else { bool check = false; if (!s.empty()) { i.. 2023. 10. 5.