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

Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป456

[๋ฐฑ์ค€,c++] 10871๋ฒˆ - X๋ณด๋‹ค ์ž‘์€ ์ˆ˜ 10871๋ฒˆ: X๋ณด๋‹ค ์ž‘์€ ์ˆ˜ ์ฒซ์งธ ์ค„์— N๊ณผ X๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N, X ≤ 10,000) ๋‘˜์งธ ์ค„์— ์ˆ˜์—ด A๋ฅผ ์ด๋ฃจ๋Š” ์ •์ˆ˜ N๊ฐœ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ์ •์ˆ˜๋Š” ๋ชจ๋‘ 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 10,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜์ด๋‹ค. www.acmicpc.net #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N, X; cin >> N >> X; for (int i = 0; i > num; if (num < X) cout 2021. 10. 25.
[๋ฐฑ์ค€,c++] 10870๋ฒˆ - ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜5 10870๋ฒˆ: ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜ 5 ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜๋Š” 0๊ณผ 1๋กœ ์‹œ์ž‘ํ•œ๋‹ค. 0๋ฒˆ์งธ ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜๋Š” 0์ด๊ณ , 1๋ฒˆ์งธ ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜๋Š” 1์ด๋‹ค. ๊ทธ ๋‹ค์Œ 2๋ฒˆ์งธ ๋ถ€ํ„ฐ๋Š” ๋ฐ”๋กœ ์•ž ๋‘ ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜์˜ ํ•ฉ์ด ๋œ๋‹ค. ์ด๋ฅผ ์‹์œผ๋กœ ์จ๋ณด๋ฉด Fn = Fn-1 + Fn-2 (n ≥ 2)๊ฐ€ www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector dp(100); dp[0] = 0; dp[1] = 1; for (int i = 2; i 2021. 10. 25.
[๋ฐฑ์ค€,c++] 10867๋ฒˆ - ์ค‘๋ณต ๋นผ๊ณ  ์ •๋ ฌํ•˜๊ธฐ 10867๋ฒˆ: ์ค‘๋ณต ๋นผ๊ณ  ์ •๋ ฌํ•˜๊ธฐ ์ฒซ์งธ ์ค„์— ์ˆ˜์˜ ๊ฐœ์ˆ˜ N (1 ≤ N ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ์—๋Š” ์ˆซ์ž๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด ์ˆ˜๋Š” ์ ˆ๋Œ“๊ฐ’์ด 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜์ด๋‹ค. www.acmicpc.net #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); int N; vectorv; cin >> N; for (int i = 0; i > number; if (!(find(v.begin(), v.end(), number) != v.end())) v.push_back(number); } sort(v.begin(), v.end());.. 2021. 10. 25.
[๋ฐฑ์ค€,c++] 10866๋ฒˆ - ๋ฑ 10866๋ฒˆ: ๋ฑ ์ฒซ์งธ ์ค„์— ์ฃผ์–ด์ง€๋Š” ๋ช…๋ น์˜ ์ˆ˜ N (1 ≤ N ≤ 10,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ๋ช…๋ น์ด ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ์ •์ˆ˜๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 100,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋ฌธ์ œ์— ๋‚˜์™€์žˆ์ง€ www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N; cin >> N; dequedq; while (N--) { string s; cin >> s; if (s == "push_back") { int num; cin >> num; dq.push_back(num); } else if (s == "push_front") .. 2021. 10. 25.
[๋ฐฑ์ค€,c++] 10845๋ฒˆ - ํ 10845๋ฒˆ: ํ ์ฒซ์งธ ์ค„์— ์ฃผ์–ด์ง€๋Š” ๋ช…๋ น์˜ ์ˆ˜ N (1 ≤ N ≤ 10,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ๋ช…๋ น์ด ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ์ •์ˆ˜๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 100,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋ฌธ์ œ์— ๋‚˜์™€์žˆ์ง€ www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N; cin >> N; queueq; while (N--) { string s; cin >> s; if (s == "push") { int num; cin >> num; q.push(num); } else if (s == "pop") { if (q.empty()) cout 2021. 10. 25.
[๋ฐฑ์ค€,c++] 10828๋ฒˆ - ์Šคํƒ 10828๋ฒˆ: ์Šคํƒ ์ฒซ์งธ ์ค„์— ์ฃผ์–ด์ง€๋Š” ๋ช…๋ น์˜ ์ˆ˜ N (1 ≤ N ≤ 10,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ๋ช…๋ น์ด ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ์ •์ˆ˜๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 100,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋ฌธ์ œ์— ๋‚˜์™€์žˆ์ง€ www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); stackst; int N; cin >> N; while (N--) { string cmd; cin >> cmd; if (cmd == "push") { int num; cin >> num; st.push(num); } else if (cmd == "top") { if (st.. 2021. 10. 25.
[๋ฐฑ์ค€,c++] 10825๋ฒˆ - ๊ตญ์˜์ˆ˜ 10825๋ฒˆ: ๊ตญ์˜์ˆ˜ ์ฒซ์งธ ์ค„์— ๋„ํ˜„์ด๋„ค ๋ฐ˜์˜ ํ•™์ƒ์˜ ์ˆ˜ N (1 ≤ N ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ๊ฐ ํ•™์ƒ์˜ ์ด๋ฆ„, ๊ตญ์–ด, ์˜์–ด, ์ˆ˜ํ•™ ์ ์ˆ˜๊ฐ€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด ์ฃผ์–ด์ง„๋‹ค. ์ ์ˆ˜๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 1 www.acmicpc.net #include #include #include #include using namespace std; bool cmp(tuplea, tupleb) { if (get(a) == get(b)) { //๊ตญ์–ด ์ ์ˆ˜๊ฐ€ ๊ฐ™์„๋•Œ if (get(a) == get(b)) { //๊ตญ์–ด์ ์ˆ˜์™€ ์˜์–ด์ ์ˆ˜๊ฐ€ ๊ฐ™์„๋•Œ if (get(a) == get(b)) { //๊ตญ์–ด,์˜์–ด,์ˆ˜ํ•™ ์ ์ˆ˜๊ฐ€ ๊ฐ™์„๋•Œ return get(a) < get(b); //์‚ฌ์ „ ์ˆœ์œผ๋กœ ์ถœ๋ ฅ } retur.. 2021. 10. 25.
[๋ฐฑ์ค€,c++] 10824๋ฒˆ - ๋„ค ์ˆ˜ 10824๋ฒˆ: ๋„ค ์ˆ˜ ์ฒซ์งธ ์ค„์— ๋„ค ์ž์—ฐ์ˆ˜ A, B, C, D๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ A, B, C, D ≤ 1,000,000) www.acmicpc.net #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string temp1, temp2; string a, b, c, d; cin >> a >> b >> c >> d; temp1 = a + b; temp2 = c + d; cout 2021. 10. 25.
[๋ฐฑ์ค€,c++] 10823๋ฒˆ - ๋”ํ•˜๊ธฐ2 10823๋ฒˆ: ๋”ํ•˜๊ธฐ 2 ๋ฌธ์ž์—ด S๊ฐ€ ์—ฌ๋Ÿฌ ์ค„์— ๊ฑธ์ณ์„œ ์ฃผ์–ด์ง„๋‹ค. S์˜ ๊ธธ์ด๋Š” ์ตœ๋Œ€ 10,000์ด๋‹ค. ํฌํ•จ๋˜์–ด์žˆ๋Š” ์ •์ˆ˜๋Š” 1,000,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s, temp; int ans = 0; while (getline(cin, s)) { for (int i = 0; i < s.length(); i++) { if (s[i] != ',') { temp += s[i]; } else { ans += stoi(temp); temp.clear(); } } } ans += stoi(tem.. 2021. 10. 24.