일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- stl
- c
- Javascript
- Flexbox
- 상태
- 알고리즘
- 에라토스테네스의 체
- Gap
- 강화학습
- 수학
- align-items
- margin
- CSS
- dataframe
- pandas
- 통신사할인
- Prefix Sums
- series
- skt membership
- Codility
- grid
- Design Pattern
- 백준
- SK바이오사이언스
- 확률
- spring
- c++
- Photoshop
- 소수
- 포토샵
Archives
- Today
- Total
sliver__
Codility : Lesson 4 (Counting Elements) - FrogRiverOne 본문
728x90
안녕하세요~~
디벨롭퍼입니다~~~

https://app.codility.com/programmers/lessons/4-counting_elements/frog_river_one/
FrogRiverOne coding task - Learn to Code - Codility
Find the earliest time when a frog can jump to the other side of a river.
app.codility.com
***********************************************************************
풀어보실 분들을 위해서 링크 걸어두었습니다.
***********************************************************************
주어진 문제는 아래와 같습니다.
A 배열에 숫자들이 담겨져있고
X의 위치까지 가기 위해서는
연속적으로 길이 전부 다 연결된 순간의 지점을 찾는 문제였습니다.
set을 사용하여 중복되는 길을 제거하면 되겠다고 생각했습니다.
그리고 X의 길을 가기 위해서는 X개 만큼의 길이 있어야 하므로
set에 담긴 사이즈가 같을 때의 인덱스를
정답으로 return 하였습니다.
아래는 제출한 코드입니다.
// you can use includes, for example:
// #include <algorithm>
#include <set>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int X, vector<int> &A) {
// write your code in C++14 (g++ 6.2.0)
int ret = -1;
int idx = 0;
std::set<int> s;
for(std::vector<int>::iterator iter = A.begin(); iter!=A.end();++iter)
{
s.insert(*iter);
if(s.size() == X)
{
ret = idx;
break;
}
idx++;
}
return
문제를 이해하는데 시간이 오래걸렸어요.
여러번을 읽었는데도 잉? 뭐지? 하고 다시 읽은 문제..
그럼 다음 문제에서 만나요
이만~~~
728x90
'CS > Codility' 카테고리의 다른 글
Codility:Lesson5(Prefix Sums) - PassingCars (0) | 2021.11.16 |
---|---|
Codility : Lesson 4 (Counting Elem) - PermCheck (0) | 2021.09.28 |
Codility : Lesson 3 (Time complexity) - TapeEquilibrium (0) | 2021.09.27 |
Codility : Lesson 3 (Time complexity) - PermMissingElem (0) | 2021.09.26 |
Codility : Lesson 3 (Time complexity) - FrogJmp (0) | 2021.09.25 |
Comments