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

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

[๋ฐฑ์ค€,c++] 10819๋ฒˆ - ์ฐจ์ด๋ฅผ ์ตœ๋Œ€๋กœ 10819๋ฒˆ: ์ฐจ์ด๋ฅผ ์ตœ๋Œ€๋กœ ์ฒซ์งธ ์ค„์— N (3 ≤ N ≤ 8)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ๋ฐฐ์—ด A์— ๋“ค์–ด์žˆ๋Š” ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋ฐฐ์—ด์— ๋“ค์–ด์žˆ๋Š” ์ •์ˆ˜๋Š” -100๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 100๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. www.acmicpc.net #include #include #include using namespace std; int n,ans,temp; int visited[201]; vectorv; void find(){ do{ for(int i=2; i>n; for(int i=0; i>inp; v.push_back(inp); } sort(v.begin(),v.end()); find(); cout 2021. 10. 24.
[๋ฐฑ์ค€,c++] 10818๋ฒˆ - ์ตœ์†Œ, ์ตœ๋Œ€ https://www.acmicpc.net/problem/10818 10818๋ฒˆ: ์ตœ์†Œ, ์ตœ๋Œ€ ์ฒซ์งธ ์ค„์— ์ •์ˆ˜์˜ ๊ฐœ์ˆ˜ N (1 ≤ N ≤ 1,000,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” N๊ฐœ์˜ ์ •์ˆ˜๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ฃผ์–ด์ง„๋‹ค. ๋ชจ๋“  ์ •์ˆ˜๋Š” -1,000,000๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 1,000,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜์ด๋‹ค. www.acmicpc.net 1๋ฒˆํ’€์ด #include #include #include using namespace std; int main() { int N; cin >> N; priority_queuepq1; //์ž‘์€ ์ˆœ์„œ๋Œ€๋กœ priority_queuepq2; //ํฐ ์ˆœ์„œ๋Œ€๋กœ for (int i = 0; i > number; pq1.pu.. 2021. 10. 24.
[๋ฐฑ์ค€,c++] 10817๋ฒˆ - ์„ธ ์ˆ˜ 10817๋ฒˆ: ์„ธ ์ˆ˜ ์ฒซ์งธ ์ค„์— ์„ธ ์ •์ˆ˜ A, B, C๊ฐ€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ A, B, C ≤ 100) www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); priority_queuepq; int A, B, C; cin >> A >> B >> C; pq.push(A); pq.push(B); pq.push(C); pq.pop(); cout 2021. 10. 24.
[๋ฐฑ์ค€,c++] 10816๋ฒˆ - ์ˆซ์ž์นด๋“œ 2 10816๋ฒˆ: ์ˆซ์ž ์นด๋“œ 2 ์ฒซ์งธ ์ค„์— ์ƒ๊ทผ์ด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ˆซ์ž ์นด๋“œ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 500,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ˆ˜๋Š” -10,000,000๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 10, www.acmicpc.net #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N; vectorv; for (int i = 0; i > number; v.push_back(number); } sort(v.begin(), v.end()); .. 2021. 10. 24.
[๋ฐฑ์ค€,c++] 10815๋ฒˆ - ์ˆซ์ž์นด๋“œ 10815๋ฒˆ: ์ˆซ์ž ์นด๋“œ ์ฒซ์งธ ์ค„์— ์ƒ๊ทผ์ด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ˆซ์ž ์นด๋“œ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 500,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ˆ˜๋Š” -10,000,000๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 10, www.acmicpc.net #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N; vectorv; for (int i = 0; i > number; v.push_back(number); } sort(v.begin(), v.end()); ci.. 2021. 10. 24.
[๋ฐฑ์ค€,c++] 10814๋ฒˆ - ๋‚˜์ด์ˆœ ์ •๋ ฌ 10814๋ฒˆ: ๋‚˜์ด์ˆœ ์ •๋ ฌ ์˜จ๋ผ์ธ ์ €์ง€์— ๊ฐ€์ž…ํ•œ ์‚ฌ๋žŒ๋“ค์˜ ๋‚˜์ด์™€ ์ด๋ฆ„์ด ๊ฐ€์ž…ํ•œ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, ํšŒ์›๋“ค์„ ๋‚˜์ด๊ฐ€ ์ฆ๊ฐ€ํ•˜๋Š” ์ˆœ์œผ๋กœ, ๋‚˜์ด๊ฐ€ ๊ฐ™์œผ๋ฉด ๋จผ์ € ๊ฐ€์ž…ํ•œ ์‚ฌ๋žŒ์ด ์•ž์— ์˜ค๋Š” ์ˆœ์„œ๋กœ ์ •๋ ฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ www.acmicpc.net #include #include #include using namespace std; bool cmp(pairx ,pairy) { return (x.first > N; vector v(N); for (int i = 0; i > v[i].first >> v[i].second; } stable.. 2021. 10. 24.
[๋ฐฑ์ค€,c++] 10811๋ฒˆ - ๋ฐ”๊ตฌ๋‹ˆ ๋’ค์ง‘๊ธฐ 10811๋ฒˆ: ๋ฐ”๊ตฌ๋‹ˆ ๋’ค์ง‘๊ธฐ ๋„ํ˜„์ด๋Š” ๋ฐ”๊ตฌ๋‹ˆ๋ฅผ ์ด N๊ฐœ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , ๊ฐ๊ฐ์˜ ๋ฐ”๊ตฌ๋‹ˆ์—๋Š” 1๋ฒˆ๋ถ€ํ„ฐ N๋ฒˆ๊นŒ์ง€ ๋ฒˆํ˜ธ๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ ํ˜€์ ธ ์žˆ๋‹ค. ๋ฐ”๊ตฌ๋‹ˆ๋Š” ์ผ๋ ฌ๋กœ ๋†“์—ฌ์ ธ ์žˆ๊ณ , ๊ฐ€์žฅ ์™ผ์ชฝ ๋ฐ”๊ตฌ๋‹ˆ๋ฅผ 1๋ฒˆ์งธ ๋ฐ”๊ตฌ๋‹ˆ, ๊ทธ ๋‹ค์Œ ๋ฐ”๊ตฌ๋‹ˆ๋ฅผ 2 www.acmicpc.net #include #include #include using namespace std; int main() { int N, M; cin >> N >> M; vectorv(N+1); for (int i = 1; i > a >> b; reverse(v.begin()+a,v.end()-N+b); } for (int i = 1; i < v.size(); i++) { cout 2021. 10. 24.
[๋ฐฑ์ค€,c++] 10809๋ฒˆ - ์•ŒํŒŒ๋ฒณ ์ฐพ๊ธฐ 10809๋ฒˆ: ์•ŒํŒŒ๋ฒณ ์ฐพ๊ธฐ ๊ฐ๊ฐ์˜ ์•ŒํŒŒ๋ฒณ์— ๋Œ€ํ•ด์„œ, a๊ฐ€ ์ฒ˜์Œ ๋“ฑ์žฅํ•˜๋Š” ์œ„์น˜, b๊ฐ€ ์ฒ˜์Œ ๋“ฑ์žฅํ•˜๋Š” ์œ„์น˜, ... z๊ฐ€ ์ฒ˜์Œ ๋“ฑ์žฅํ•˜๋Š” ์œ„์น˜๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ถœ๋ ฅํ•œ๋‹ค. ๋งŒ์•ฝ, ์–ด๋–ค ์•ŒํŒŒ๋ฒณ์ด ๋‹จ์–ด์— ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค๋ฉด -1์„ ์ถœ www.acmicpc.net #include #include using namespace std; int main() { string S; string check = "abcdefghijklmnopqrstuvwxyz"; cin >> S; for (int i = 0; i < check.length(); i++) { if (S.find(check[i]) == string::npos) cout 2021. 10. 23.
[๋ฐฑ์ค€,c++] 10808๋ฒˆ - ์•ŒํŒŒ๋ฒณ ๊ฐœ์ˆ˜ 10808๋ฒˆ: ์•ŒํŒŒ๋ฒณ ๊ฐœ์ˆ˜ ๋‹จ์–ด์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” a์˜ ๊ฐœ์ˆ˜, b์˜ ๊ฐœ์ˆ˜, …, z์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ถœ๋ ฅํ•œ๋‹ค. www.acmicpc.net #include #include using namespace std; vectoralphabet = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' }; vectorans(alphabet.size()); int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; for (int i = 0; i < s.length(); i++) { for .. 2021. 10. 23.