imported>vkdnjdldnjsw |
imported>황창재 |
| (4 intermediate revisions by 2 users not shown) |
| Line 1: |
Line 1: |
| __TOC__
| |
|
| |
| = 오늘의 문제 =
| |
| * [https://www.codeground.org/practice/practiceProbView.do?probId=12|방속의 거울]
| |
| = 참가자 =
| |
|
| |
| = 코드 =
| |
| == 15이원준 ==
| |
| // 아래 기본 제공된 코드를 수정 또는 삭제하고 본인이 코드를 사용하셔도 됩니다.
| |
| #include <cstdio>
| |
| #include <iostream>
| |
| #include <stdlib.h>
| |
| using namespace std;
| |
|
| |
| int main(int argc, char** argv) {
| |
| /* 아래 freopen 함수는 input.txt 를 read only 형식으로 연 후,
| |
| 앞으로 표준 입력(키보드) 대신 input.txt 파일로 부터 읽어오겠다는 의미의 코드입니다.
| |
| 만약 본인의 PC 에서 테스트 할 때는, 입력값을 input.txt에 저장한 후 freopen 함수를 사용하면,
| |
| 그 아래에서 scanf 함수 또는 cin을 사용하여 표준입력 대신 input.txt 파일로 부터 입력값을 읽어 올 수 있습니다.
| |
| 또한, 본인 PC에서 freopen 함수를 사용하지 않고 표준입력을 사용하여 테스트하셔도 무방합니다.
| |
| 단, Codeground 시스템에서 "제출하기" 할 때에는 반드시 freopen 함수를 지우거나 주석(//) 처리 하셔야 합니다. */
| |
| //freopen("input.txt", "r", stdin);
| |
|
| |
| setbuf(stdout, NULL);
| |
| int TC;
| |
| int test_case;
| |
|
| |
| scanf("%d", &TC); // cin 사용 가능
| |
| for (test_case = 1; test_case <= TC; test_case++) {
| |
| // 이 부분에서 알고리즘 프로그램을 작성하십시오.
| |
| int n;
| |
| scanf("%d", &n);
| |
| int** arr = (int**)malloc(sizeof(int*) * (n + 2));
| |
| for (int i = 0; i < (n + 2); i++){
| |
| arr[i] = (int*)malloc(sizeof(int) * (n + 2));
| |
| }
| |
| int** visit = (int**)malloc(sizeof(int*) * (n + 2));
| |
| for (int i = 0; i < (n + 2); i++){
| |
| visit[i] = (int*)malloc(sizeof(int) * (n + 2));
| |
| }
| |
| for (int i = 0; i < n + 2; i++){
| |
| for (int j = 0; j < n + 2; j++){
| |
| visit[i][j] = 0;
| |
| if (i == 0 || i == n + 1 || j == 0 || j == n + 1){
| |
| arr[i][j] = -1;
| |
| }
| |
| else{
| |
| scanf("%1d", &arr[i][j]);
| |
| }
| |
| }
| |
| }
| |
| int x = 1, y = 1;
| |
| pair<int, int> dir = make_pair(0, 1);
| |
| int ans = 0;
| |
| while (arr[x][y] != -1){
| |
| if (arr[x][y] != 0 && visit[x][y] == 0){
| |
| ans++;
| |
| visit[x][y] = 1;
| |
| }
| |
| pair<int, int> next;
| |
| switch (arr[x][y]){
| |
| case 0:
| |
| next = dir;
| |
| break;
| |
| case 1:
| |
| next.second = dir.first * -1;
| |
| next.first = dir.second * -1;
| |
| break;
| |
| case 2:
| |
| next.first = dir.second;
| |
| next.second = dir.first;
| |
| break;
| |
| }
| |
| dir = next;
| |
| x += dir.first;
| |
| y += dir.second;
| |
| }
| |
|
| |
|
| |
| // 이 부분에서 정답을 출력하십시오.
| |
| printf("Case #%d\n", test_case); // cout 사용 가능
| |
| printf("%d\n", ans);
| |
| }
| |
|
| |
| return 0; // 정상종료 시 반드시 0을 리턴해야 합니다.
| |
| }
| |
| = 아이디어 =
| |
| == 15이원준 ==
| |
| * brute force 알고리즘 최고!
| |
|
| |
|