๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)315

[๋ฐฑ์ค€,c++] 11724๋ฒˆ - ์—ฐ๊ฒฐ ์š”์†Œ์˜ ๊ฐœ์ˆ˜ 11724๋ฒˆ: ์—ฐ๊ฒฐ ์š”์†Œ์˜ ๊ฐœ์ˆ˜ ์ฒซ์งธ ์ค„์— ์ •์ ์˜ ๊ฐœ์ˆ˜ N๊ณผ ๊ฐ„์„ ์˜ ๊ฐœ์ˆ˜ M์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N ≤ 1,000, 0 ≤ M ≤ N×(N-1)/2) ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ M๊ฐœ์˜ ์ค„์— ๊ฐ„์„ ์˜ ์–‘ ๋์  u์™€ v๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ u, v ≤ N, u ≠ v) ๊ฐ™์€ ๊ฐ„์„ ์€ ํ•œ ๋ฒˆ๋งŒ ์ฃผ www.acmicpc.net #include #include using namespace std; int map[1001][1001]; int visited[1001]; int cnt = 0; int N, M; void dfs(int x) { visited[x] = 1; for (int i = 1; i > N>>M; for (int i = 0; i > a >> b; map[a][b].. 2021. 10. 31.
[๋ฐฑ์ค€,c++] 11722๋ฒˆ - ๊ฐ€์žฅ ๊ธด ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด https://www.acmicpc.net/problem/11722 11722๋ฒˆ: ๊ฐ€์žฅ ๊ธด ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด ์ˆ˜์—ด A๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ฐ€์žฅ ๊ธด ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ˆ˜์—ด A = {10, 30, 10, 20, 20, 10} ์ธ ๊ฒฝ์šฐ์— ๊ฐ€์žฅ ๊ธด ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด์€ A = {10, 30, 10, 20, 20, 10} www.acmicpc.net #include #include #include using namespace std; /* ์ˆ˜์—ด์„ ์—ญ์ˆœ์œผ๋กœ ์ƒ๊ฐํ•˜์—ฌ ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด์„ ๊ตฌํ•˜๊ฒŒ ๋˜๋ฉด ๋œ๋‹ค. */ int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vectorarr.. 2021. 10. 31.
[๋ฐฑ์ค€,c++] 11721๋ฒˆ - ์—ด ๊ฐœ์”ฉ ๋Š์–ด ์ถœ๋ ฅํ•˜๊ธฐ #include #include using namespace std; int main() { string N; getline(cin, N); for (int i = 0; i < N.size(); i++) { cout 2021. 10. 31.
[๋ฐฑ์ค€,c++] 11720๋ฒˆ - ์ˆซ์ž์˜ ํ•ฉ #include using namespace std; int main() { int cnt; char N; int sum = 0; cin >> cnt; while (cnt-- > 0) { cin >> N; sum += (N - '0'); } cout 2021. 10. 31.
[๋ฐฑ์ค€,c++] 11719๋ฒˆ - ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๊ธฐ2 11719๋ฒˆ: ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๊ธฐ 2 ์ž…๋ ฅ์ด ์ฃผ์–ด์ง„๋‹ค. ์ž…๋ ฅ์€ ์ตœ๋Œ€ 100์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ๊ณต๋ฐฑ, ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๊ฐ ์ค„์€ 100๊ธ€์ž๋ฅผ ๋„˜์ง€ ์•Š์œผ๋ฉฐ, ๋นˆ ์ค„์ด ์ฃผ์–ด์งˆ ์ˆ˜๋„ ์žˆ๊ณ , ๊ฐ ์ค„์˜ ์•ž ๋’ค์— ๊ณต๋ฐฑ์ด www.acmicpc.net #include #include using namespace std; int main() { string s; for (int i = 0; i < 100; i++) { getline(cin, s); //์—”ํ„ฐ๊ฐ€ ๋‚˜์˜ค๊ธฐ ์ „๊นŒ์ง€ ํ•œ ์ค„ ์ž…๋ ฅ cout 2021. 10. 31.
[๋ฐฑ์ค€,c++] 11718๋ฒˆ - ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๊ธฐ #include #include using namespace std; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); while (getline(cin, s)) { cout 2021. 10. 31.
[๋ฐฑ์ค€,c++] 11659๋ฒˆ - ๊ตฌ๊ฐ„ ํ•ฉ ๊ตฌํ•˜๊ธฐ4 11659๋ฒˆ: ๊ตฌ๊ฐ„ ํ•ฉ ๊ตฌํ•˜๊ธฐ 4 ์ฒซ์งธ ์ค„์— ์ˆ˜์˜ ๊ฐœ์ˆ˜ N๊ณผ ํ•ฉ์„ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ํšŸ์ˆ˜ M์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” N๊ฐœ์˜ ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ˆ˜๋Š” 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ์…‹์งธ ์ค„๋ถ€ํ„ฐ M๊ฐœ์˜ ์ค„์—๋Š” ํ•ฉ์„ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ๊ตฌ๊ฐ„ i์™€ j www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N, M,temp=0; cin >> N >> M; vectorv(N + 1), sum(N+1); for (int i = 0; i > v[i]; temp += v[i]; sum[i + 1] = temp; } for (int i = 0.. 2021. 10. 31.
[๋ฐฑ์ค€,c++] 11656๋ฒˆ - ์ ‘๋ฏธ์‚ฌ ๋ฐฐ์—ด 11656๋ฒˆ: ์ ‘๋ฏธ์‚ฌ ๋ฐฐ์—ด ์ฒซ์งธ ์ค„์— ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. S๋Š” ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๊ธธ์ด๋Š” 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. www.acmicpc.net #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s,temp; cin >> s; vectorv; for (int i = 0; i < s.length(); i++) { for (int k = i; k < s.length(); k++) { temp += s[k]; } v.push_back(temp); temp.clear(); } sort(v.begin(), v.end()); for (strin.. 2021. 10. 31.
[๋ฐฑ์ค€,c++] 11652๋ฒˆ - ์นด๋“œ 11652๋ฒˆ: ์นด๋“œ ์ค€๊ทœ๋Š” ์ˆซ์ž ์นด๋“œ N์žฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์ˆซ์ž ์นด๋“œ์—๋Š” ์ •์ˆ˜๊ฐ€ ํ•˜๋‚˜ ์ ํ˜€์žˆ๋Š”๋ฐ, ์ ํ˜€์žˆ๋Š” ์ˆ˜๋Š” -262๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 262๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ์ค€๊ทœ๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์นด๋“œ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ฐ€์žฅ ๋งŽ์ด ๊ฐ€์ง€ www.acmicpc.net #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector number; int cnt = 1, max = 1; long long ans; for (int i = 0; i > num; number.push_back(num); } .. 2021. 10. 31.