전체 글 164

백준 14405번 피카츄 ( C++ )

문제https://www.acmicpc.net/problem/14405 해설주어진 조건대로 조건문만 사용하면 되는 간단한 문제 코드123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263#include iostream> using namespace std; string s; int main(){  ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL);   cin >> s;  int s_len = s.length();  for (int i = 0; i  s_len; i++)  {    if ..

백준 5430번 AC ( C++ )

문제https://www.acmicpc.net/problem/5430 해설문자열을 숫자로 바꾸는 로직 + 뒤집는 것을 마지막에 한번만 하도록 하는 로직이 핵심 코드123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778#include iostream>#include deque>#include algorithm> using namespace std;int t, n, num, num_arr;string p, line;char tmp; int main(){  cin >> t;   while (t--)  {..

백준 13244번 Tree ( C++ )

문제https://www.acmicpc.net/problem/13244 해설기본적인 트리의 개념을 알고 있는지 물어보는 문제 코드123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475#include iostream>#include algorithm>#include vector>#include queue> using namespace std; int t, n, m, node1, node2, visited[1004];vectorint> edge[1004]; void bfs(int num){  visited[num..

백준 14391번 종이 조각 ( C++ )

문제https://www.acmicpc.net/problem/14391 해설모든 경우의 수를 확인하는 로직을 생각해 내야하는문제비트 마스킹을 이용해서 해결 코드1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768#include iostream>#include algorithm> using namespace std; int mp[8][8], n, m, ret;string line; int go(int num){  int sum = 0;  for (int i = 0; i  n; i++)  {    int tmp = 0;    for (..

백준 11723번 집합 ( C++ )

문제https://www.acmicpc.net/problem/11723 해설비트마스킹을 이용하여 경우의 수만 나눠주면 되는 문제시간초과가 발생할 수 있기 때문에 아래 방법을 사용하거나 char배열을 이용해야함12ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cs 코드1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162#include iostream>#include algorithm> using namespace std;int n, m, s;string cal; int main(){  ios..

백준 2234번 성곽 ( C++ )

문제https://www.acmicpc.net/problem/2234 해설커넥티드 컴퍼넌트를 이용한 문제옆의 집합과 합치는 과정을 신경써야함 코드1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283#include iostream>#include algorithm> using namespace std; int visited[54][54], mp[54][54], ret_cnt, ret_max, ret_max2, n, m, tmp, cnt_room[2504];int dx[4] = {-..

백준 1062번 가르침 ( C++ )

문제https://www.acmicpc.net/problem/1062 해설비트마스킹을 이용하는 문제모든 경우의 수를 고려하기에는 너무 많음 => 재귀 호출을 이용한 제한된 호출코드12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455// k가 0일 수 있음#include iostream>#include algorithm> using namespace std;int n, k, ret, word[54], basic;string line; void go(int idx, int num, int check){  if (check == k)  {    int tmp = 0;    for (..

백준 14890번 경사로 ( C++ )

문제https://www.acmicpc.net/problem/14890 해설경우의 수만 잘 나누면 어렵지 않았던 문제가로 세로 로직을 따로 구현하는 것이 아닌 map1[i][j] = map2[j][i]를 이용하여 하나의 로직으로 가로 세로 모두 확인코드12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879#include iostream>#include algorithm> using namespace std;int n, l, mp[104][104], mp2[104][104], ret; void g..

백준 17471번 케리맨더링 ( C++ )

문제https://www.acmicpc.net/problem/17471 해설bfs, 비트마스킹을 통해 해결방문확인 하는 과정이 생각보다 까다로웠음코드123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103#include iostream>#include algorithm>#include vector>#include queue>using namespace std; const int INF = 987654321..