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

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

[๋ฐฑ์ค€,c++] 13239๋ฒˆ - Combinations 13239๋ฒˆ: Combinations When we have a set of n elements from which we take k elements, we have a combination. For example, if we have a set with the numbers from 1 to 5, we have the following different combinations: 1-combinations (1 element from the set each time): (1), (2), (3 www.acmicpc.net ์กฐํ•ฉ์„ ํŒŒ์Šค์นผ ์‚ผ๊ฐํ˜• ์ ํ™”์‹์„ ์ด์šฉํ•˜์—ฌ DP๋กœ ํ‘ผ Solution ์ด๋‹ค. #include #define MOD 1000000007 using namespace std; int main().. 2021. 11. 4.
[๋ฐฑ์ค€,c++] 13171๋ฒˆ - A 13171๋ฒˆ: A ์Œ์ด ์•„๋‹Œ ๋‘ ์ •์ˆ˜ A, X ๊ฐ€ ์žˆ์„ ๋•Œ AX์„ ๊ตฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ƒ๊ฐํ•ด๋ณด์ž. ๋ฌผ๋ก  ์ด ์ˆ˜๋Š” ๋งค์šฐ ํด ์ˆ˜ ์žˆ๊ธฐ์—, 1,000,000,007 (= 109 + 7)๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๋ฅผ ๊ตฌํ•  ๊ฒƒ์ด๋‹ค. a mod x๋ฅผ a๋ฅผ x๋กœ ๋‚˜๋ˆด์„ ๋•Œ์˜ ๋‚˜๋จธ์ง€๋ผ๊ณ  ํ‘œ www.acmicpc.net 10^4๋ฅผ ๊ตฌํ• ๋•Œ 101010*10 ๋ณด๋‹ค๋Š” 10^2 * 10^2 ๊ฐ€ ๋” ๋น ๋ฅธ ๊ฒฝ์šฐ์ž„์„ ์ƒ๊ฐํ•˜์—ฌ ํ’€์ดํ•œ๋‹ค. a^b์ผ๋•Œ b๊ฐ€ ํ™€์ˆ˜์ธ ๊ฒฝ์šฐ๋Š” a๋ฅผ ํ•œ๋ฒˆ ๋” ๊ณฑํ•ด์ค˜์•ผ ํ•œ๋‹ค. #include #define ll unsigned long long int #define mod 1000000007 using namespace std; ll pow(ll a, ll b) { if (b == 0) return 1; else { ll n = .. 2021. 11. 4.
[๋ฐฑ์ค€,c++] 13163๋ฒˆ - ๋‹‰๋„ค์ž„์— ๊ฐ“ ๋ถ™์ด๊ธฐ 13163๋ฒˆ: ๋‹‰๋„ค์ž„์— ๊ฐ“ ๋ถ™์ด๊ธฐ ์ฒซ ๋ฒˆ์งธ ์ค„์—๋Š” ๋‹‰๋„ค์ž„์˜ ์ˆ˜ N(1 ≤ N ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘ ๋ฒˆ์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ์Œ์ ˆ ๋‹จ์œ„๋กœ ์ชผ๊ฐ  ๋‹‰๋„ค์ž„์ด ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ์ค„์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž์™€ ๊ณต๋ฐฑ๋งŒ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉฐ, ์ชผ๊ฐ  ๋‹‰๋„ค์ž„์˜ ์ด www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N; cin >> N; cin.ignore(); for (int i = 0; i < N; i++) { string s; getline(cin, s); int cnt = 0; for (int j = 0; j < s.length(); j++) { cnt++; if (s.. 2021. 11. 4.
[๋ฐฑ์ค€,c++] 1316๋ฒˆ - ๊ทธ๋ฃน ๋‹จ์–ด ์ฒด์ปค 1316๋ฒˆ: ๊ทธ๋ฃน ๋‹จ์–ด ์ฒด์ปค ๊ทธ๋ฃน ๋‹จ์–ด๋ž€ ๋‹จ์–ด์— ์กด์žฌํ•˜๋Š” ๋ชจ๋“  ๋ฌธ์ž์— ๋Œ€ํ•ด์„œ, ๊ฐ ๋ฌธ์ž๊ฐ€ ์—ฐ์†ํ•ด์„œ ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒฝ์šฐ๋งŒ์„ ๋งํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด, ccazzzzbb๋Š” c, a, z, b๊ฐ€ ๋ชจ๋‘ ์—ฐ์†ํ•ด์„œ ๋‚˜ํƒ€๋‚˜๊ณ , kin๋„ k, i, n์ด ์—ฐ์†ํ•ด์„œ ๋‚˜ํƒ€๋‚˜๊ธฐ ๋•Œ www.acmicpc.net #include #include using namespace std; int cnt = 0; bool flag = true; void check(string s) { for (int i = 0; i < s.length() - 2; i++) { if (s[i] != s[i + 1]) { //1๊ณผ 2์˜ ๋‹จ์–ด๊ฐ€ ๋‹ค๋ฅผ๋•Œ for (int k = i + 2; k < s.length(); k++) { //3๋ถ€ํ„ฐ ๋๊นŒ์ง€ ์ฒดํฌํ•ด 1๊ณผ ๊ฐ™์€ ๋‹จ์–ด๊ฐ€.. 2021. 11. 4.
[๋ฐฑ์ค€,c++] 13023๋ฒˆ - ABCDE 13023๋ฒˆ: ABCDE ๋ฌธ์ œ์˜ ์กฐ๊ฑด์— ๋งž๋Š” A, B, C, D, E๊ฐ€ ์กด์žฌํ•˜๋ฉด 1์„ ์—†์œผ๋ฉด 0์„ ์ถœ๋ ฅํ•œ๋‹ค. www.acmicpc.net #include #include #include using namespace std; vectorgraph[2001]; int visited[2001]; int N,M; //N=์‚ฌ๋žŒ์˜ ์ˆ˜, M=์นœ๊ตฌ ๊ด€๊ณ„์˜ ์ˆ˜ bool check; void dfs(int start,int depth){ visited[start]=1; if(depth==4){ check=true; return; } else{ for(int i=0; i>N>>M; for(int i=0; i>a>>b; graph[a].push_back(b); graph[b].push_back(a); } for(int i=0.. 2021. 11. 4.
[๋ฐฑ์ค€,c++] 1302๋ฒˆ - ๋ฒ ์ŠคํŠธ์…€๋Ÿฌ 1302๋ฒˆ: ๋ฒ ์ŠคํŠธ์…€๋Ÿฌ ์ฒซ์งธ ์ค„์— ์˜ค๋Š˜ ํ•˜๋ฃจ ๋™์•ˆ ํŒ”๋ฆฐ ์ฑ…์˜ ๊ฐœ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ์ด ๊ฐ’์€ 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ์ฑ…์˜ ์ œ๋ชฉ์ด ์ž…๋ ฅ์œผ๋กœ ๋“ค์–ด์˜จ๋‹ค. ์ฑ…์˜ ์ œ๋ชฉ์˜ ๊ธธ์ด๋Š” 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๊ณ  www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); mapm; int N; cin >> N; while (N--) { string s; cin >> s; m[s]++; } int ans = 0; for (auto i = m.begin(); i != m.end(); i++) { ans = max(ans, i->second); //๊ฐ€์žฅ .. 2021. 11. 4.
[๋ฐฑ์ค€,c++] 1292๋ฒˆ - ์‰ฝ๊ฒŒ ํ‘ธ๋Š” ๋ฌธ์ œ 1292๋ฒˆ: ์‰ฝ๊ฒŒ ํ‘ธ๋Š” ๋ฌธ์ œ ์ฒซ์งธ ์ค„์— ๊ตฌ๊ฐ„์˜ ์‹œ์ž‘๊ณผ ๋์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ •์ˆ˜ A, B(1 ≤ A ≤ B ≤ 1,000)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฆ‰, ์ˆ˜์—ด์—์„œ A๋ฒˆ์งธ ์ˆซ์ž๋ถ€ํ„ฐ B๋ฒˆ์งธ ์ˆซ์ž๊นŒ์ง€ ํ•ฉ์„ ๊ตฌํ•˜๋ฉด ๋œ๋‹ค. www.acmicpc.net #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int start,end; cin>>start>>end; vectorv; for(int k=1; k 2021. 11. 4.
[๋ฐฑ์ค€,c++] 12851๋ฒˆ - ์ˆจ๋ฐ”๊ผญ์งˆ2 12851๋ฒˆ: ์ˆจ๋ฐ”๊ผญ์งˆ 2 ์ˆ˜๋นˆ์ด๋Š” ๋™์ƒ๊ณผ ์ˆจ๋ฐ”๊ผญ์งˆ์„ ํ•˜๊ณ  ์žˆ๋‹ค. ์ˆ˜๋นˆ์ด๋Š” ํ˜„์žฌ ์  N(0 ≤ N ≤ 100,000)์— ์žˆ๊ณ , ๋™์ƒ์€ ์  K(0 ≤ K ≤ 100,000)์— ์žˆ๋‹ค. ์ˆ˜๋นˆ์ด๋Š” ๊ฑท๊ฑฐ๋‚˜ ์ˆœ๊ฐ„์ด๋™์„ ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋งŒ์•ฝ, ์ˆ˜๋นˆ์ด์˜ ์œ„์น˜๊ฐ€ X์ผ ๋•Œ www.acmicpc.net #include #include #define MAX 100001 using namespace std; int N,K; //N= ์ˆ˜๋นˆ์ด๊ฐ€ ์žˆ๋Š” ์œ„์น˜, K= ๋™์ƒ์ด ์žˆ๋Š” ์œ„์น˜ int short_time=MAX,cnt; int visited[MAX]; void bfs(int start,int time){ queueq; q.push({start,0}); visited[start]=1; while(!q.empty()){ int sta.. 2021. 11. 4.
[๋ฐฑ์ค€,c++] 12813๋ฒˆ - ์ด์ง„์ˆ˜ ์—ฐ์‚ฐ 12813๋ฒˆ: ์ด์ง„์ˆ˜ ์—ฐ์‚ฐ ์ด 100,000 ๋น„ํŠธ๋กœ ์ด๋ฃจ์–ด์ง„ ์ด์ง„์ˆ˜ A์™€ B๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, A & B, A | B, A ^ B, ~A, ~B๋ฅผ ํ•œ ๊ฐ’์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. www.acmicpc.net #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); bitsetA,B; cin>>A>>B; cout 2021. 11. 2.