문제 링크: https://www.acmicpc.net/problem/14454
14454번: Secret Cow Code
The cows are experimenting with secret codes, and have devised a method for creating an infinite-length string to be used as part of one of their codes. Given a string s, let F(s) be s followed by s "rotated" one character to the right (in a right rotation
www.acmicpc.net
주어진 index가 길이가 두배가 되기전 어떤 index에서 온것인지 역추적 하면 됨.
예시
COW 8
n -> 출력할 알파벳 index
------------------------------
0 -> 0
1 -> 1
2 -> 2
------------------------------ n이 3보다 작으면 해당 index 출력
3 -> 2
4 -> 0
5 -> 1
------------------------------ 나머지가 2, 0, 1, 따라서 % 3
6 -> 5 -> 1
7 -> 0
8 -> 1
9 -> 2
10 -> 3 -> 2
11 -> 4 -> 0
------------------------------ 나머지가 5, 0, 1, 2, 3, 4, 따라서 % 6
12 -> 11 -> 4 -> 0
13 -> 0
14 -> 1
15 -> 2
16 -> 3 -> 2
.
.
.
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
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s;
ll n;
cin >> s >> n;
n -= 1;
ll sz = s.size();
while(1) {
if(n < sz) break;
ll tmp = sz;
while(tmp <= n) {
tmp *= 2;
}
tmp /= 2;
n = (n - 1) % tmp;
}
cout << s[n] << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'USACO > Silver' 카테고리의 다른 글
백준 14465 소가 길을 건너간 이유 5 (USACO February 2017 Silver 2번) (0) | 2020.04.20 |
---|---|
백준 14464 소가 길을 건너간 이유 4 (USACO February 2017 Silver 1번) (0) | 2020.04.19 |
백준 14453 Hoof, Paper, Scissors (USACO January 2017 Silver 2번) (0) | 2020.04.04 |
백준 14452 Cow Dance Show (USACO January 2017 Silver 1번) (0) | 2020.04.03 |
백준 14172 Moocast (USACO December 2016 Silver 3번) (0) | 2020.04.03 |