전체 글 (2344) 썸네일형 리스트형 C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 1325번:효율적인 해킹(BFS) 답 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960//가장 많이 연결되어 있는 간선을 가지고 있는 점을 찾아야 한다.#include #include #include #include using namespace std;int n, m,u,v,c[10001],d[10001];//각 정점에 연결된 간선의 개수가 몇인지 저장하는 vector a[10001];vector p(10001);//가장 많은 간전을 가지고 있는 점을 저장함void BFS(int x){ queue q; q.push(x); while (!q.empty()) { int x = q.front(); .. C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 1786번:찾기 답 KMP문제입니다//p는 찾으려는 문자열 //s는 주어지는 문자열/*KMP Algorithm -------------------------------------------------------------------------------------------1.시간 복잡도 O(n+m) - > pi배열을 만드는 시간 m(원하는 문자열의 길이), 주어진 문자열에서 원하는 문자열 찾는 시간 n2.Preprocessing - > pi배열 만들기 : 원하는 문자열은 p,주어진 문자열을 s라 했을 때,1)p의 접두사와, 접미사를 비교하여 p의 인덱스 마다 그 둘이 같은 것의 길이를 저장한다,같지 않으면 pi[i]=02)while문을 pi의 인덱스가 하나 증가할 때마다 돌린다(line 28) - > 현재 p[i]의 문자.. C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 2133번:타일채우기 답 //3xn을 채우는데 1x2,2x1 타일로 총 세가지로 채울 수 있다.//가짓 수 : D[n] - > n이 짝수여야지만 주어진 타일로 채울 수 있다.//D[i] = 3*D[i-2]+2*D[i-4]+2*D[i-6]....+2*D[i-2*j]//D[i] = 3*D[i-2]+2*sum[i-4]라고 나타낼 수 있다.1234567891011121314#include using namespace std;int n,d[31];int main() { cin >> n; d[0] = 1; for (int i = 2; i C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 1547번:공 답 123456789101112131415161718#include #include using namespace std;int main() { int t, s=0,a[4] = { 0,1,0,0 }; cin >> t; while (t--) { int x, y; cin >> x >> y; swap(a[x], a[y]); } for (int i = 1; i C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 5522번:카드 게임 답 1234567891011#include using namespace std;int main() { int sum=0, x; for (int i = 0; i > x; sum += x; } cout C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 1475번:방번호 답 123456789101112131415161718#include #include using namespace std;int a[10], big;int main() { string k; cin >> k; for (int i = 0; i C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 10866번:덱 답 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667#include #include #include using namespace std;int main() { string k; deque d; int n,x; cin >> n; while (n--) { cin >> k; if (k == "push_front") { cin >> x; d.push_front(x); } else if (k == "push_back") { cin >> x; d.push_back(x); } else if (k == "pop_back") { if (!d.empty.. C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 2161번:카드1 답 1234567891011121314151617181920#include #include using namespace std;int main() { int n; queue q; cin >> n; for (int i = 1; i 이전 1 ··· 252 253 254 255 256 257 258 ··· 293 다음