본문 바로가기

Algorithm

알고리즘 > 백트래킹A > 영역 구하기(1457) Question 문제 링크 Solving* 어려웠던 점좌표가 (0,0)~(5,7)로 주어져서 배열을 어떻게 채워넣어야 할지에 대한 혼란이 왔다. 결국 영역의 크기를 받을 때, 채워질 영역을 계산하여 map[0][0]을 2로 채웠다. 123456789for (int i0 = (세로1 + 1); i0 더보기
실력키우기 > 수학 응용 > 소수(1740) Question 문제 링크 Solving '에라토스테네스의 체' 에 대해 공부해봅시다. 소수를 더 쉽고 빠르게 구할 수 있습니다. CodeColored By Color Scripter™1234567891011121314151617181920212223242526272829303132333435363738394041424344#include #include #pragma warning(disable:4996) int m, cnt = 1, sum, min, sosu[1000000], nInput, i = 1; int main(){ FILE *fin = fopen("input.txt", "r"); FILE *fout = fopen("output.txt", "w"); fscanf(fin, "%d\n%d", &n.. 더보기
알고리즘 > BFS > 장기(1106) Question 문제 링크 Solving주의점장기의 馬는 (+1, +2)로 이동할 수 있기 때문에 자칫 벽의 범위 밖으로 나갈 수도 있다. 이를 방지하는 예외처리를 꼭 한다. (해당 예외를 생각하지 못 하여 마지막 테스트 통과하지 못 했다.) CodeColored By Color Scripter™12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576#include #include #pragma warning(disable:4996) using namespace std; typedef struct _bloc.. 더보기
[Stack 응용]접시 꺼내기 / dish Question 문제 링크 Solving CodeColored By Color Scripter™12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667#include #include #pragma warning(disable:4996) using namespace std; stack washing;char dish[32];int flag, cnt_all, cnt_answer, cnt_dish, start_alpha;int answer[1000000];void algo(int dishnum, int alpha); // 다음 결과 접시;int.. 더보기
[C/C++] 스택(배열) CodeColored By Color Scripter™123456789101112131415161718192021222324252627282930313233343536#include #define MAX 2int stack[MAX];int top = -1; void push(int value){ if (top >= MAX - 1) { printf("Error\n"); return; } stack[++top] = value;} int pop(void){ if (top 더보기
알고리즘 > 자료구조A > 탑(1809) Question 문제 링크 Solving CodeColored By Color Scripter™123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657#include #include #pragma warning(disable:4996) using namespace std; typedef struct _fac{ int idx; int val;}fac; int n, cnt;fac building[500005];stack box;int answer[500005]; int main(){ FILE *fin = fopen("input.txt", "rt"); FILE *fout = fo.. 더보기
실력키우기 > 문자열 > 문자열변환(2518) Question문제 링크 CodeColored By Color Scripter™123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051#include #pragma warning(disable:4996) int n, t;typedef struct _changer{ char a; char b;}changer; changer list[52];char answer[100005]; int main(){ int i = 1; char dir, tmp; FILE *fin = fopen("input.txt", "rt"); FILE *fout = fopen("output.txt", "wt"); // 입력 fsc.. 더보기
알고리즘 > BFS > 저글링 방사능 오염(1078) Question 문제 링크 Solving * 미리 생각하는 예외- 맵 크기와 저글링 수와 관계 없이 저글링 한마리만 피해 받는 상황 CodeColored By Color Scripter™12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879#include #include using namespace std; typedef struct _zugling{ int xz; int yz; char stat; int order;}zugling; int a, b, c, d, cnt_time, cnt_num;.. 더보기
알고리즘 > 자료구조A > 불쾌한날(1141) Questionhttp://www.jungol.co.kr/prog/Hanal/hanalView.php?qs_code=1141 Solving 스택에 들어올 다음 수와 top과 비교한다.1) top이 더 크다면 그냥 push, 2) top이 작다면 pop하고, 3) 다음 top과 다시 비교하여, top이 크다면 1) 로, 작다면 2) 로 간다. 주어진 테스트 케이스로 그려보면 아래와 같이 진행된다. 2 2 4 4 1 5 5 5 5 6 6[0] [1] [2] [3] [4] [5] 4 1 2 1 2 1 3 0 1 0 1 0 위 표에서 4 1 2 1 2 1은 각 단계에서 push된 값이 몇 단계나 살아 남는지 적은 것이다.5의 경우 0단계에서 push되어 3단계까지 살아남고 4단계에서 pop이 된다. 4 1 2 .. 더보기
[Algorithm]명심하자!!! 1. 주어진 테스트 케이스는 끝까지 돌려보고, 내가 도출한 답과 정답을 비교해본다.2. 예외처리는 잘 되었는지 두번 생각한다.3. 0일때나 값이 가장 클 때의 경우는 반드시 넣어본다. 더보기