Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- hackerrank
- CSRF
- 취약점진단
- StringBuilder
- java
- metasploit
- Suninatas
- meterpreter
- algotithm
- 미터프리터
- SQLMap
- 정보시스템
- HTML Injection
- stock price
- Algorithm
- study
- 취약점
- 써니나타스
- wpscan
- 모의해킹
- programmers
- 라우터
- todo
- Router
- todo List
- SQL Injection
- leetcode
- 모드 설정
- ToDoList
- 웹해킹
Archives
- Today
- Total
보안 / 개발 챌린저가 목표
[AlphaGo Study] [HackerRank] [JAVA] Strange Counter 본문
문제 설명
Bob has a strange counter. At the first second, it displays the number 3. Each second, the number displayed by the counter decrements by 1 until it reaches 1.
The couner counts down in cycles. In next second, the timer resets to 2 × the initial number for the prior cycle and continues counting down. The diagram below shows the counter values for each time t in the first three cycles:
Find and print the value displayed by the counter at time t.
제한 사항
- Complete the strangeCounter function in the editor below. It should return the integer value displayed by the counter at time t.
- strangeCounter has the following parameters(s): ⇒ t: an integer
- 1 ≤ t ≤ 10¹²
- Subtask : 1 ≤ t ≤ 100000 for 60% of the maximum score.
- Input Format : A single integer denoting the value of t.
- Output Format : Print the value displayed by the strange counter at the given time t.
입출력 예
t | result |
4 | 6 |
입출력 예 설명
#예제
Time t = 4 marks the beginning of the second cycle. It is double the number displayed at the beginning of the first cycle: 2 × 3 = 6. This is also shown in the diagram in the Problem Statement above.
https://www.hackerrank.com/challenges/strange-code/problem
문제를 풀기 전 THINK
- value의 처음 값은 3이다.
- value의 값이 1이 되면 다음 주기로 넘어간다.
- 다음 주기의 처음 value 값 = 전 주기 처음 value × 2
- value의 처음 값 = time의 처음 값 + 2
나의 Solution
public class StrangeCounter {
long strangeCounter(long t) {
long time_top = 1;
long value_top = 3;
// 각 주기의 맨 위의 값 구하기
while(time_top <= t) {
time_top += value_top;
value_top = time_top + 2;
}
// 구하고 싶은 시간의 다음 주기 time_top에서 구하고 싶은 시간 빼면 됨
return (time_top - t);
}
}
'Development > Algorithm' 카테고리의 다른 글
[AlphaGo Study] [LeetCode] [JAVA] 21. Merge Two Sorted Lists (0) | 2020.09.24 |
---|---|
[AlphaGo Study] [LeetCode] [JAVA] 104. Maximum Depth of Binary Tree (0) | 2020.09.22 |
[AlphaGo Study] [HackerRank] [JAVA] Halloween Sale (0) | 2020.09.14 |
[AlphaGo Study] [Programmers] [JAVA] 기능개발 (0) | 2020.09.10 |
[AlphaGo Study] [Programmers] [JAVA] 체육복 (0) | 2020.09.08 |
Comments