반응형

Programming 298

백준 16943 c++ [숫자재배치]

#include #include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a, b, c; c = -1; cin >> a >> b; string str = to_string(a); sort(str.begin(), str.end());//next_permutation을 사용하기 위해 오름차순 정렬 do { int num = stoi(str); if (str[0] == '0')continue;//문자열의 첫번째 문자가 0이면 정수로변환했을때 자리수가 변경됨으로 순열X if (num < b && c < num)//b보다 작으면서 현..

백준 1063 c++ [킹]

#include #include #include #include #include #include using namespace std; int map[8][8];//체스판 string str, str2, od;//킹의위치입력, 돌의위치입력, 움직이는정보 int n;//움직이는횟수 vectorv(2);//킹,돌의 좌표저장할 vector int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> str >> str2 >> n; for (int i = 0; i < str.length(); i++)//킹의위치 저장, 좌표상 0,0 은 체스판으로 8,a { if (i == 0) { int idx = 0; for (char j = '..

[백준] 2667 단지번호붙이기 c++

#include #include #include #include #include #include using namespace std; int n;//지도의크기, 지도는 정사각형 int map[26][26]; bool visited[26][26]; int dx[4] = { 1,0,-1,0 };//상하좌우탐색 int dy[4] = { 0,1,0,-1 }; int cnt = 0;//총 단지 수 vectorv;//단지내 집의 수 void bfs(int x,int y) { queueq; q.push({ x,y }); visited[x][y] = true; map[x][y] = -1; int temp = 1;//입력받은 좌표값부터 시작함으로 temp는 1부터시작, temp는 단지내 집의 수 while (!q.emp..

[백준] 7569 토마토 c++

#include #include #include #include #include using namespace std; //1익은토마토, 0익지않은토마토, -1비어있는칸 //저장될때부터 익어있으면 0 출력, 모두 익지못하는 상황이면 -1 출력 typedef struct { int x; int y; int z; }node; int n, m, h;//세로,가로,높이 칸수 int map[101][101][101]; bool visited[101][101][101]; int dx[6] = { 0,0,0,0,1,-1 }; int dy[6] = { 0,1,0,-1,0,0 }; int dz[6] = { 1,0,-1,0,0,0 }; int answer = 0; int num = 0; int num2 = 0; vector..

[백준] 7576 토마토 c++

#include #include #include #include #include #include #include #include #include using namespace std; int n, m; int map[1001][1001];//map bool visited[1001][1001];//방문여부배열 vectorstart;//익은 토마토 저장하는 vector int answer = 0;//정답저장할 변수 int dx[4] = { 1,0,-1,0 };//상하좌우탐색을 위한 배열 int dy[4] = { 0,1,0,-1 }; bool check = true; void bfs() { queueq; for (int i = 0; i < start.size(); i++)//익은 토마토들의 좌표 queue에 p..

백준 11403 경로찾기 [c++]

#include #include #include #include #include #include #include #include using namespace std; int n; int temp; vectorv[101]; bool visited[101]; void dfs(int start) { stacks; s.push(start); while (!s.empty()) { int x = s.top(); s.pop(); for (int i = 0; i < v[x].size(); i++) { int xx = v[x][i]; if (xx == 0)continue;//xx의 값이 1인경우가 연결된 정점 if (visited[i])continue; s.push(i);//연결된 인덱스 push 및 방문 표시 visi..

반응형