์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต
-
[C++] ์ผ์ฑ 4014. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ํ์ฃผ๋ก ๊ฑด์ค์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:16
(1์๊ฐ 30๋ถ) ์๊ฐ๋๋๋๋ก ์ฝ๋ฉํ๋ฉด์ ์์ธ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ๋ ์๊ฐ์ด ์ค๋๊ฑธ๋ฆฐ๋๋.. #include #include #include using namespace std; int arr[20][20]; bool bridge[20][20]; int N, X; int main() { int T; cin >> T; for (int t = 1; t > N >> X; for (int i = 0; i > arr[i][j]; } } int count = 0; for (int i = 0; i < N; i++) { int j = 0; int value = arr[i][j++]; while (j < N) { if (arr[i][j] < val..
-
[C++] ๋ฐฑ์ค 9372๋ฒ. ์๊ทผ์ด์ ์ฌํ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:15
๋์ผ์ค ํด์ฆ์ธ์ค; MST๊ตฌํ๋ ์ค ์์๋๋ฐ ์ฐ๊ฒฐ ๊ทธ๋ํ๋ฅผ ์ฃผ๊ณ ๋ชจ๋ ์ ์ ์ ์ด์ ์ ์๋ ์ต์ ๊ฐ์ ์ ์๋ฅผ ๊ตฌํ๋ผ ํ๋ฉด ๋ฌด์กฐ๊ฑด ์ ์ ์ ์ - 1 ์ด ์ ๋ต. #include #include using namespace std; int nation[1001][1001] = {0, }; bool visited[1001] = {false, }; int main(){ int T; cin >> T; for(int t=0; t> nation_num >> plane_num; for(int m=0; m> a >> b; nation[a][b] = 1; nation[b][a] = 1; } cout
-
[C++] ์ผ์ฑ 1952. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ์์์ฅ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:14
๋ชจ๋ ๊ฒฝ์ฐ์ ์ ๊ตฌํด๋ณด๊ธฐ #include #include using namespace std; int cost[4] = {0, }; int month[12] = {0, }; int min_cost = 99999999; void solution(int index, int total) { if (index >= 12) { if (min_cost > total) min_cost = total; return; } solution(index + 1, total + cost[0] * month[index]); solution(index + 1, total + cost[1]); solution(index + 3, total + cost[2]); } int main() { int T; cin >> T; for (int..
-
[C++] ์ผ์ฑ 2382. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ๋ฏธ์๋ฌผ ๊ฒฉ๋ฆฌ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:14
#include using namespace std; struct group { int x; int y; int num; int dir; }; int dir[5][2] = { {0,0},{-1,0},{1,0},{0,-1},{0,1} }; group arr[1000] = {}; int dir_change(int now_dir) { if (now_dir == 1 || now_dir == 3) { return now_dir + 1; } else if (now_dir == 2 || now_dir == 4) { return now_dir - 1; } } int main() { int T; cin >> T; for (int t = 1; t > N >> M >> K; for (int i = 0; i < K; i++)..
-
[C++] ๋ฐฑ์ค 9935๋ฒ. ๋ฌธ์์ด ํญ๋ฐ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:13
#include #include using namespace std; int main() { string s1, s2; getline(cin, s1); getline(cin, s2); int size = s2.size(); int idx = 0; while (s1.find(s2) != std::string::npos) { int index = s1.find(s2, idx); //s1 = s1.substr(0, index) + s1.substr(index + size, s1.size()); s1.erase(index, size); idx = index - size; if (idx < 0) idx = 0; } if (s1.empty()) cout s2; string s3 = ""; int size = s2...
-
[C++] ์ผ์ฑ 2383. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ์ ์ฌ ์์ฌ์๊ฐ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:12
#include #include #include #include #include using namespace std; #define PII pair #define INF 99999999 int min_dist; int arr[11][11]; vector peoples; vector stairs; int cal_dist(pair a, pair b) { return abs(a.first - b.first) + abs(a.second - b.second); } int cal_stairs(vector stairs1, vector stairs2) { int stairs1_size = stairs1.size(); int stairs2_size = stairs2.size(); int stairs1_time = 0; ..
-
[C++] ํ๋ก๊ทธ๋๋จธ์ค ์ฌ ์ฐ๊ฒฐํ๊ธฐ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:12
#include #include #include #include using namespace std; #define PII pair priority_queue vertex; vector *node; vector visited; int addEdge(int node); int prim(int n); int solution(int n, vector costs) { int answer = 0; node = new vector[n]; for(int i=0; i
-
[C++] ํ๋ก๊ทธ๋๋จธ์ค ๋จ์ด ๋ณํ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:11
#include #include using namespace std; int number = 9999999; int N = 0; int string_size = 0; int string_check(string first, string second){ int count = 0; for(int i=0; i step){ number = step; return; } for(int i=0; i