일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- BOJ
- kakao
- 리뷰
- review
- Recursive
- Netflix
- 해설
- 2020
- silver
- usaco
- 추천
- Movie
- 카카오
- 영어
- Algorithm
- health
- Greedy
- 알고리즘
- parametric search
- benefits
- array
- BFS
- 영화
- 완전탐색
- 넷플릭스
- coding
- 코딩 테스트
- 백준
- 수능
- 나는솔로
Archives
- Today
- Total
Young
Secret Cow Code 본문
728x90
반응형
https://www.acmicpc.net/problem/14454
제가 영어를 잘 못해서 해석이 어려웠지만, 예제를 한 번 보니 이해를 단번에 해버렸습니다.
N 값보다 문자열의 길이가 커질 때까지 이 행동을 반복할 필요가 있을까요?
일단 입력으로 들어오는 N 값이 10^18인 것을 보니 절대 그럴수는 없을거라는 느낌이 드네요.
이렇게 값이 크게 주어지면 보통 binary search / dynamic programming / pattern 찾기 정도를 생각해
볼 수 있습니다.
느낌상 pattern 찾기를 해보면 될 것 같아요. 뭔가 규칙이 있을 것 같습니다.
새로 추가되는 문자가 없고, 추가하는 문자열도 원래 문자열에 규칙적인 연산을 한 후에 붙이는 것이라
(한칸 쉬프트하고, 뒤집어서 뒤에 붙이는게 전부이니..)
N 값을 반복적인 계산으로 원래 초기 문자열 길이 안으로 가져오면 되겠습니다.
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
32
33
34
35
36
37
38
|
#include <math.h>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <string>
#include <string.h>
#define endl '\n'
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
ll n;
string s;
int main() {
FastIO;
cin >> s;
cin >> n;
ll f = s.size();
while (f < n) f <<= 1;
while (n > s.size()) {
while(n <= f) f >>= 1;
n -= f;
n -= 1;
if (n == 0) n = f;
}
cout << s[n - 1];
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
728x90
반응형
'코딩 테스트 대비 추천 문제 > USACO' 카테고리의 다른 글
Hoof, Paper, Scissors (Silver) (0) | 2019.04.05 |
---|---|
Cow Dance Show (0) | 2019.04.05 |
Why Did the Cow Cross the Road III (Silver) (0) | 2019.04.05 |
Moocast (0) | 2019.04.04 |
Why Did the Cow Cross the Road (Silver) (0) | 2019.04.04 |