티스토리 뷰

Algorithm

[SWEA] D4 8382 방향 전환 (java)

코딩브론즈 2020. 12. 16. 22:48

swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWyNQrCahHcDFAVP&categoryId=AWyNQrCahHcDFAVP&categoryType=CODE

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

풀이

 

1) 좌표가 -100~100 이므로 2차원 배열 생성 int map[201][201] 

2) 규칙 찾기

3) 대각선을 2씩 증가시키며 map을 채움

4) 나머지는 규칙대로 넣음

5) 반대편은 복사

6) |x1-x2| , |y1-y2| 의 좌표값이 답

 

주의사항

 

1) 딱히..

 

package com.SWEA;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.Arrays;
import java.util.StringTokenizer;
/**
 * @author yhs
 * @date 2020. 12. 3
 * @see
 * @mem
 * @time
 * @caution
 * [고려사항]
 * 1) 대각선은 2씩 증가
 * 2) 좌표가 -100~100 이다 -> 0~200으로 편하게하자
 * [입력사항]
 * [출력사항]
 */
public class SWEA_D4_8382_방향전환 {
	static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer tokens;
	static int T, map[][] = new int[201][201];
	public static void main(String[] args) throws NumberFormatException, IOException {
		input = new BufferedReader(new StringReader(src));
		for(int rc=0; rc<map.length; rc++) {
			map[rc][rc] = 2*rc;
		}
		
		for(int c=0; c<map.length; c++) {
			boolean flag = false;
			for(int r=c; r>=0; r--) {
				if(flag) {
					map[r][c] = map[c][c]-1;
					flag = false;
				}else {
					map[r][c] = map[c][c];
					flag = true;
				}
			}	
		}
		
		for(int c=0; c<map.length; c++) {
			for(int r=c; r<map.length; r++) {
				map[r][c] = map[c][r]; 
			}	
		}
		
		T = Integer.parseInt(input.readLine());
		for(int t=1; t<=T; t++) {
			tokens = new StringTokenizer(input.readLine());
			int x1 = Integer.parseInt(tokens.nextToken());
			int y1 = Integer.parseInt(tokens.nextToken());
			int x2 = Integer.parseInt(tokens.nextToken());
			int y2 = Integer.parseInt(tokens.nextToken());
			
			int r = Math.abs(x1-x2);
			int c = Math.abs(y1-y2);
			
			System.out.println("#"+t+" "+map[r][c]);
		}
		
	}
 
	static String src =
			"3\r\n" + 
			"0 0 1 0\r\n" + 
			"-1 -1 0 0\r\n" + 
			"0 0 0 2";
}

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함