728x90
반응형

백준 144

백준, BOJ, 11403번, 플로이드 : C++ [CPP] ★★★★

플로이드 문제를 하나 더 살펴봤다 이것이 더욱 플로이드 알고리즘의 핵심인 최단거리에 가까울 것이다. 역시 노드는 100개정도로 별로 없다. https://www.acmicpc.net/problem/11404 #맞는 풀이 #include #include #define MAX 105 #define INF 123456789 using namespace std; int n, m; int path[MAX][MAX]; int main() { cin >> n >> m; //테이블 초기화(처음엔 모두 INF) (1부터 n까지) for (int i = 1; i > from >> to >> cost; path[from][to] = min(cost, path[from][to]); //방향 그래프 } //자기 자신으로 돌아오..

백준, BOJ, 1504번, 최소비용2 : C++ [CPP] ★

한 번 갔던 간선에 대해 다시 갈 수 있으므로 연결해줄 때 양방향으로 연결해줘야 했다. 남들은 잘보이지만 나는 이것만 30분 넘게.. 걸렸다. 그리고 어차피 최단경로 = 최단경로 + 최단경로라고 생각해도 된다. https://www.acmicpc.net/problem/1504 #맞는 풀이 #include #include #include #include #include #include #define MAX 803 #define INF INT_MAX using namespace std; int N, E; vector adj[MAX]; //인접행렬 long long dist[MAX]; long long dist1[MAX]; //v1을 위한 long long dist2[MAX]; //v2를 위한 int v1, ..

백준, BOJ, 14500번, 테트로미노: C++ [CPP]

이것도 정말 구현문제로써 시키는대로 하면 된다. 다만 어떻게 구현할까? 의 선택지에서 DFS를 골랐다면 고생을 덜 할 것이었다 https://www.acmicpc.net/problem/14500 #맞는 풀이 #include #include #include using namespace std; int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; int N,M; int map[500][500]; bool visited[500][500]; // 멍청했따.. 어차피 4칸을 사용하는 건데... DFS로 풀었으면 되었다는 힌트를 듣고.. 현타온다. //즉 DFS로 4칸 탐색하는 과정에 일자 모양도 있고 네모도있고 기역자도 있다. //다만 ㅗ 모양만 DFS로 탐색은 불가능하다. in..

백준, BOJ, 21608번, 상어초등학교: C++ [CPP]

이것도 정말 구현문제로써 시키는대로 하면 된다. 다만 범위에 신경쓰도록 사용자 입력만이 범위가 아니란 것을 명심하자 https://www.acmicpc.net/problem/21608 #맞는 풀이 #include #include #include #define X first #define Y second using namespace std; int seat[21][21];//자리 배치 1~N만 쓸 것임 int dx[4] = { 1,-1,0,0 }; //방향 int dy[4] = { 0,0,1,-1 }; //방향 int good[5] = { 0,1,10,100,1000 }; //점수 int N; vector info[401]; //학생 번호와 선호하는 학생을 저장 int main() { cin >> N; i..

백준, BOJ, 20055번, 컨베이어 벨트 위의 로봇 : C++ [CPP]

그냥 시키는 대로 하면 된다. 다만 빼먹으면 안된다. 모든 조건을 빼먹으면 안된다. https://www.acmicpc.net/problem/20055 #맞는 풀이 #include #include #define X first #define Y second using namespace std; using ll = long long; int N, K; // 칸과 제한 deque deq; // 로봇이 있는지 1,0 내구도 int int main() { cin >> N >> K; int num = 2 * N; while (num--) { int x; cin >> x; deq.push_back({0,x }); //로봇이 없는 채로 deq 초기화 } int stage = 0; while (1) { stage++;/..

백준, BOJ, 3190번, 뱀 : C++ [CPP]

문제대로 구현하면 된다. 하지만 어렵지는 않았다. 그냥.. 중간에 if 조건문에서 == 써야할 것을 =으로 써서 30분 날렸다. https://www.acmicpc.net/problem/3190 # 맞는 풀이 #include #include #include #define X first #define Y second using namespace std; //하 상 우 좌 -> 좌측 위 기준 int dx[4] = { 1,-1,0,0 }; int dy[4] = { 0,0,1,-1 }; int N, K, L; int map[100][100]; char direction[10001]; queue q; //꼬리 잘라내기 //1.머리를 hx,hy로 옮김, 게임시간 cnt int Move(int hx, int hy, ..

백준, BOJ, 1753번, 최단경로 : C++ [CPP] ★★★★★

어렵다. 다익스트라를 배웠지만 코딩테스트에서 다시 쓰니까 어렵다 https://www.acmicpc.net/problem/1753 #맞은 풀이 #include #include #include #include #include #define INF INT_MAX using namespace std; int V,E,start; //벡터를 원소로 가지는 배열 -> vector adj[20001]; // 인접행렬 from,(weight,to) //-> adj[1] = {3,5} 의 의미 1번 정점에서 5번으로 가는 가중치 3 //이런 그래프에서 최단거리 => 다익스트라 테이블 int table[20001]; //최소 간선을 위한 minHeap {거리, 정점 번호} -> 일반적으로 first를 기준으로 오름차순으로..

백준, BOJ, 16637번, 괄호추가하기 : C++ [CPP]

어려웠다. 사실 생각은 났는데 작성하기가 힘들다. 아직 구현하는 능력이 부족하다. 100문제밖에 안풀었는데 잘하길 바라는 것은 사치겠지 더군다나 시간제한이 있는 것으로 봐선.. 어려워보였지만 다행히 20개가 넘는 식은 안나와서 풀 수 있었다. https://www.acmicpc.net/problem/16637 #맞는 풀이 #include #include #include #include using namespace std; int N; string s; int ans_M = INT_MIN; //괄호를 씌웠을 때, 안씌웠을 때 모두 조사해본다. //괄호에 의해서만 연산 순서가 정해진다 (모두 연산 순위 같음) //연산 int operation(int a, int b, char c){ int result; /..

백준, BOJ, 1543번, 문서 검색 : C++ [CPP]

어렵지 않았다 다만 첫번째로 못풀었다. 왜 그런지 고찰해보자 https://www.acmicpc.net/problem/1543 #맞은 풀이 #include #include using namespace std; int main() { string s; string target; getline(cin, s); getline(cin, target); int size = target.size(); int cnt = 0; while (1) { int idx = s.find(target); //찾았으면 해당 문자열에서 삭제 if (idx != string::npos) { auto it = s.begin() + idx; //s.erase(it, it+size); -> 삭제 s = s.substr(idx + size)..

백준, BOJ, 1120번, 문자열 : C++ [CPP]

사실 이것은 정말 직관을 요하는 문제다. 브루트포스에 있지만.. 정말 브루트포스처럼 전수조사인지는 의문이다. https://www.acmicpc.net/problem/1120 #맞는 풀이 #include #include #include #include using namespace std; int main(){ string a; string b; cin >> a >> b; int lengthA = a.size(); int lengthB = b.size(); int numToAdd = lengthB-lengthA; int m = INT_MAX; // 최솟값 //lengthA에 대해서 lengthB의 어느 부분이랑 가장 매치가 되는지 //-> 가장 맞는 부분을 구한다면 해당 부분에서의 차이가 곧 전체의 차이임..

728x90
반응형