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 |
Tags
- 백준
- 알고리즘
- 다익스트라
- 유니온 파인드
- Team Fortress 2
- 우선순위 큐
- 그래프
- DFS
- BFS
- 투 포인터
- 백트래킹
- Unreal Engine 5
- VR
- ue5
- 누적 합
- 재귀
- 자료구조
- 정렬
- 브루트포스
- 유니티
- 수학
- XR Interaction Toolkit
- c++
- 구현
- 스택
- 시뮬레이션
- 그리디 알고리즘
- 문자열
- 다이나믹 프로그래밍
- 트리
Archives
- Today
- Total
1일1알
백준 2331번 반복수열 C++ 본문
https://www.acmicpc.net/problem/2331
2331번: 반복수열
첫째 줄에 반복되는 부분을 제외했을 때, 수열에 남게 되는 수들의 개수를 출력한다.
www.acmicpc.net
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int64 a;
int p;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> a >> p;
vector<int64> v;
set<int64> s;
v.push_back(a);
s.insert(a);
int ans = 0;
while (true) {
int64 currNum = v.back();
int64 nextNum = 0;
string str = to_string(currNum);
for (int i = 0; i < str.length(); i++) {
nextNum += pow((str[i] - '0'), p);
}
auto it = s.find(nextNum);
if (it == s.end()) {
s.insert(nextNum);
v.push_back(nextNum);
}
else {
for (int i = 0; i < v.size(); i++) {
if (v[i] == nextNum) {
ans = i;
break;
}
}
break;
}
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 15671번 오델로 C++ (0) | 2023.05.11 |
---|---|
백준 25206번 너의 평점은 C++ (0) | 2023.05.09 |
백준 17828번 문자열 화폐 C++ (0) | 2023.05.07 |
백준 2615번 오목 C++ (0) | 2023.05.06 |
백준 17829번 222-풀링 C++ (0) | 2023.05.05 |