반응형

알고리즘 37

[이취코] 알고리즘 유형별 기출문제: 그리디 - 2. 곱하기 혹은 더하기 (Python)

2. 곱하기 혹은 더하기 문제 각 자리가 숫자(0부터 9)로만 이루어진 문자열 S가 주어졌을 때, 왼쪽부터 오른쪽으로 하나씩 모든 숫자를 확인하며 숫자 사이에 ‘X’ 혹은 ‘+’ 연산자를 넣어 결과적으로 만들어질 수 있는 가장 큰 수를 구하는 프로그램을 작성하시오. 단, +보다 x를 먼저 계산하는 일반적인 방식과는 달리 모든 연산은 왼쪽에서부터 순서대로 이루어진다고 가정함. 만들어질 수 있는 가장 큰 수는 항상 20억 이하의 정수가 되도록 입력이 주어짐 예시 02984라는 문자열이 주어지면, 만들어질 수 있는 가장 큰 수는 ((((0+2)*9)8)*4)=576임 567이 주어지면 가능한 가장 큰 수는 567=210임 입출력 조건 입력: 첫째 줄에 여러 개의 숫자로 구성된 하나의 문자열 S가 주어짐 (1 ..

[이취코] 알고리즘 유형별 기출문제: 그리디 - 1. 모험가 길드 (Python)

1. 모험가 길드 문제 한 마을에 N명의 모험가가 있다. 모험가 길드에서는 N명의 모험가를 대상으로 ‘공포도’를 측정했는데, ‘공포도’가 높은 모험가는 쉽게 공포를 느껴 위험 상황에서 제대로 대처할 능력이 떨어진다. 모험가 길드장인 동빈이는 모험가 그룹을 안전하게 구성하고자 공포도가 X인 모험가는 반드시 X명 이상으로 구성한 모험가 그룹에 참여해야 여행을 떠날 수 있도록 규정했다. 동빈이는 최대 몇 개의 모험가 그룹을 만들 수 있을지 궁금하다. 동빈이를 위해 N명의 모험가에 대한 정보가 주어졌을 때, 여행을 떠날 수 있는 그룹 수의 최댓값을 구하는 프로그램을 작성하시오. 단, 몇 명의 모험가는 마을에 그대로 남아 있어도 되므로 모든 모험가를 특정 그룹에 넣을 필요는 없음 예시 N=5, 공포도 2 3 1 ..

[리트코드 LeetCode] Search for a Range (Find First and Last Position of Element in Sorted Array) (Python)

Search for a Range (Find First and Last Position of Element in Sorted Array) https://leetcode.com/explore/interview/card/top-interview-questions-medium/110/sorting-and-searching/802/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. l..

[리트코드 LeetCode] Find Peak Element (Python)

Find Peak Element https://leetcode.com/explore/interview/card/top-interview-questions-medium/110/sorting-and-searching/801/ 분류: Top Interview Questions - Medium - Sorting and Searching Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore...

[리트코드 LeetCode] Generate Parentheses (Python)

Generate Parentheses https://leetcode.com/explore/interview/card/top-interview-questions-medium/109/backtracking/794/ 분류: Top Interview Questions - Medium - Backtracking Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문..

[리트코드 LeetCode] Sqrt(x) (Python)

Sqrt(x) https://leetcode.com/explore/interview/card/top-interview-questions-medium/113/math/819/ 분류: Top Interview Questions - Medium - Math 문제 음이 아닌 정수 x가 주어졌을 때 x의 제곱근을 계산해라. 결과는 가장 가까운 정수로 내림하여 반환 값도 음이 아닌 정수여야 한다. built-in 연산자나 함수를 사용하지 않고 해결해야 한다. type x: int / rtype: int 예시 Example 1: Input: x = 4 Output: 2 Explanation: The square root of 4 is 2, so we return 2. Example 2: Input: x = 8 Out..

[리트코드 LeetCode] Factorial Trailing Zeroes (Python)

Factorial Trailing Zeroes https://leetcode.com/explore/interview/card/top-interview-questions-medium/113/math/816/ 분류: Top Interview Questions - Medium - Math Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문제 주어진 정수 n에..

[리트코드 (LeetCode)] Kth Largest Element in an Array (Python)

Kth Largest Element in an Array https://leetcode.com/explore/interview/card/top-interview-questions-medium/110/sorting-and-searching/800/ 분류: Top Interview Questions - Medium - Sorting and Searching Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for y..

[리트코드 (LeetCode)] Pascal's Triangle (Python)

Pascal’s Triangle https://leetcode.com/explore/featured/card/top-interview-questions-easy/99/others/601/ 분류: Top Interview Questions - Easy - Others Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문제 주어진 정수 numRow에 대해 파..

[백준] 14889: 스타트와 링크 (Python)

14889: 스타트와 링크 https://lemon27.tistory.com/22 [백준] 1748: 수 이어 쓰기 1 (Python) 1748: 수 이어 쓰기 1 https://www.acmicpc.net/problem/1748 1748번: 수 이어 쓰기 1 첫째 줄에 N(1 ≤ N ≤ 100,000,000)이 주어진다. www.acmicpc.net 문제 1부터 N까지의 수를 이어서 쓰면 다음과 같이 새로운.. lemon27.tistory.com 문제 오늘은 스타트링크에 다니는 사람들이 모여서 축구를 해보려고 한다. 축구는 평일 오후에 하고 의무 참석도 아니다. 축구를 하기 위해 모인 사람은 총 N명이고 신기하게도 N은 짝수이다. 이제 N/2명으로 이루어진 스타트 팀과 링크 팀으로 사람들을 나눠야 한다..

반응형