Programming399 백준 큐 1966 #include #include #include using namespace std;int t, n, m, x, r;int main() { scanf("%d", &t); while (t--) { r = 0; queue qu; priority_queue pq; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", &x); qu.push({ x,i }); pq.push(x); } while (qu.size()) { int here = qu.front().first; int num = qu.front().second; qu.pop(); if (pq.top() == here) { r++; pq.pop(); if (num == m)break; } el.. 2018. 1. 29. 백준 DFS, BFS /*DFS, BFS 가 왜 큐문제에 들어있습니꽈그래프를 DFS 로 탐색한 결과와 BFS 로 탐색한 결과를 출력하는 프로그램을 작성해보도록 하겠스니다. 정점 번호가 작은 것을 먼저 방문하고, 더 이ㅏㅇ 방문할 수 있는 점이 없는 경우종료합니다. 정점 번호정점의 개수, 간선의 개수 ㅏㅁ색을 시작할 정점의 번호가 주어집니다. 입력으로 주어지는 간선은 양방향입니다. 1 2 3 41 1 1 12 1 13 1 14 1 1 1 이렇게 되어 있고 스타트는 1에서 한다? 1,2 에서 한다이것인가요. */ #include #include using namespace std; int Graph[1001][1001] = { 0 };int DFSvisit[1001] = { 0 };int BFSvisit[1001] = { 0 }.. 2018. 1. 29. 백준 큐 /*zbfmf rngusgks ekdma audfudzbfmf sjgsms rjt tkdlwm dpaxl vmfhsxm qor dhzpdldy.*/ #include #include #include using namespace std; int main(void) {int N;int num;string str;queue que;cin >> N;for (int i = 0; i > str;if (str == "push") {cin >> num;que.push(num);} else if (str == "front") {if (!que.empty()) {cout 2018. 1. 29. 백준 괄호 2504 #include #include #include using namespace std;int main() {string n;cin >> n;stack s;int ans = 0, k = 0, l = 0, mul = 1;for (int i = 0; i < n.length(); i++) {char now = n[i];switch(now) {case '(' :++k;s.push(now);mul *= 2;if (i + 1 < n.length() && n[i + 1] == ')')ans += mul;break;case '[' :++l;s.push(now);mul *= 3;if (i + 1 < n.length() && n[i + 1] == ']')ans += mul;break;case ')' :--k;s.pop();m.. 2018. 1. 29. 백준 스택 괄호 #include #include #include using namespace std; bool Check(string str) {int len = (int)str.length();stack st; for (int i = 0; i > n;for (int i = 0; i > str; if (Check(str)) {cout 2018. 1. 29. 백준 스택 사용 /*wkfyfmf sjgsms vntldlqrndhk wkfyffm Qhqsms vkq dlqrnrk rkxdk wpdlf ajswj emfdjrks wkfyrk wpdlf skwnddp skdhsms tmxordp vntlgksms tnstjsms qksemtl dh반드시 오름차순을 지키도록 한다고 ㅏㅂ니다. 임의의 수열이 주어졌을 때 스택을 이용해 그 수열을 만들 수 있는지없는 지 있따면 어떤 수넛로 푸시와 팝을 연산을 수행해야 하는지 알아낼 수 있습니다. 지금 넣었다고 가정하는 겁니까? 4 3 6 8 7 5 2 1 8 6 3 4*/ #include #include using namespace std; int main() {int stack[100000];char res[200000];int i, n.. 2018. 1. 29. 백준 스택 /*오케이 이렇게 하나씩 풀어나가면 됩니다. 정수를 저장하는 스택을 구현한 다음,입력으로 주어지는 명령을 처리하는 프로그램을 작성하세요.푸시 팝, 사이즈 엠티, 탑 스택의 가장 위에 있는 정수를 출력하세요.팝이랑 탑이랑 구분할 필요가 있ㅅ습니다.첫째 줄에 주어지는 명령의 수가 주어집니다. 스택에 대해서 모르니 이것은 정답을 보고풀어보도록 하겠습니다. */ #include #include #include using namespace std; int main(void) {int n;cin >> n; stack st;string str; for (int i = 0; i > str;if (str == "push") {int num;cin >> num;st.push(num);}else.. 2018. 1. 29. 백준 소수 골드바흐 #include #include #define SIZE 10001using namespace std;int isNotPrime[SIZE]; void eratosthenes() {for (int i = 2; i*i > 1;for(i=j=mid; i 2018. 1. 29. 백준 소수 #include #include using namespace std;int c[250000], n, ans;vector a;int main() {for (int i = 2; i > n;ans = 0;if (n == 0) break;for (int i = 0; i n && a[i] 2 * n)break;}cout 2018. 1. 29. 백준 소수 체 #include using namespace std; int main() {int i, j, m, n, a[1000001] = { 0,1 };cin >> m >> n; for (i = 2; i 2018. 1. 29. 이전 1 ··· 16 17 18 19 20 21 22 ··· 40 다음