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
- Team Fortress 2
- 누적 합
- 백트래킹
- 자료구조
- 트리
- 유니티
- XR Interaction Toolkit
- c++
- 그래프
- 스택
- ue5
- 정렬
- DFS
- 투 포인터
- VR
- Unreal Engine 5
- 시뮬레이션
- 알고리즘
- 재귀
- 구현
- 브루트포스
- 수학
- 다익스트라
Archives
- Today
- Total
1일1알
백준 1802번 종이 접기 C++ 본문
종이의 중간지점을 정해서 접었을 때 대칭되는 점들이 모두 다르다면 동호의 규칙대로 접을 수 있는 것이다.
종이가 전부 접힐 때까지 분할 정복을 통해 해결할 수 있다.
그리고 문자열의 길이가 항상 2^n - 1이라고 했기 때문에 길이가 짝수가 되는 경우는 고려하지 않아도 된다.
#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 <unordered_map>
#include <unordered_set>
#include <iomanip>
using namespace std;
using ll = long long;
bool isAns = true;
string str;
void rec(int idx, int n) {
if (n == 0) return;
for (int i = 1; i <= n; i++) {
if (str[idx + i] == str[idx - i]) {
isAns = false;
return;
}
}
rec(idx / 2, n / 2);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
cin >> str;
rec(str.length() / 2, str.length() / 2);
if (isAns) cout << "YES" << "\n";
else cout << "NO" << "\n";
isAns = true;
}
};
'알고리즘' 카테고리의 다른 글
백준 14600번 샤워실 바닥 깔기 (Small) C++ (0) | 2022.02.08 |
---|---|
백준 1275번 커피숍2 C++ (0) | 2022.02.07 |
백준 6576번 쿼드 트리 C++ (0) | 2022.02.06 |
백준 3678번 카탄의 개척자 C++ (0) | 2022.02.04 |
백준 10253번 헨리 C++ (0) | 2022.02.04 |