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 |
Tags
- BFS
- 누적 합
- 알고리즘
- ue5
- 그리디 알고리즘
- 구현
- 시뮬레이션
- XR Interaction Toolkit
- 투 포인터
- 문자열
- DFS
- 자료구조
- VR
- 다익스트라
- Unreal Engine 5
- 트리
- 우선순위 큐
- 백준
- 다이나믹 프로그래밍
- 정렬
- 스택
- Team Fortress 2
- 유니티
- c++
- 브루트포스
- 유니온 파인드
- 그래프
- 수학
- 재귀
- 백트래킹
Archives
- Today
- Total
1일1알
백준 17828번 문자열 화폐 C++ 본문
https://www.acmicpc.net/problem/17828
17828번: 문자열 화폐
첫 번째 줄에 문자열의 길이 N(1 ≤ N ≤ 5,000,000)과, 문자열의 가치를 나타내는 정수 X(1 ≤ X ≤ 500,000,000)가 공백으로 구분되어 주어진다.
www.acmicpc.net
그리디하게 a의 최대 개수를 구한다.
#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;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int64 n, x;
cin >> n >> x;
if (n * 26 < x || n > x) {
cout << "!";
}
else {
int a = 0;
for (int i = n; i >= 0; i--) {
if (i + (n - i) * 26 >= x) {
a = i;
break;
}
}
for (int i = 0; i < a; i++) cout << 'A';
int cnt = (x - a) / 26;
if ((x - a) % 26 != 0) {
cout << char(65 + (x - a) % 26 - 1);
}
for (int i = 0; i < cnt; i++) {
cout << 'Z';
}
}
}
'알고리즘' 카테고리의 다른 글
백준 25206번 너의 평점은 C++ (0) | 2023.05.09 |
---|---|
백준 2331번 반복수열 C++ (0) | 2023.05.08 |
백준 2615번 오목 C++ (0) | 2023.05.06 |
백준 17829번 222-풀링 C++ (0) | 2023.05.05 |
백준 2508번 사탕 박사 고창영 C++ (0) | 2023.05.04 |