문제링크
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV2b-QGqADMBBASw
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Solution {
static Queue<int []> queue;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int t=0;t<T;t++) {
queue = new LinkedList<>();
int p = sc.nextInt();
int q = sc.nextInt();
findNumber(p);
findNumber(q); // 두 개 좌표 구하기
int x=0,y=0;
while(!queue.isEmpty()) {
int arr[] = queue.poll();
x += arr[0];
y += arr[1];
}
//System.out.println("x = "+x+" y = "+y);
int startPoint = 1;
int result = 1;
while(true) {
if(startPoint == x)
break;
startPoint++;
result = result + startPoint;
}
//System.out.println("x축 :"+startPoint+" result :"+result);
int endPoint = 1;
while(true) {
if(y == endPoint)
break;
result = result + startPoint;
startPoint++;
endPoint++;
}
System.out.println("#"+(t+1)+" "+result);
}
}
static void findNumber(int num) {
int find = 1;
int startNum = 1;
while(startNum<num) {
find++;
startNum += find;
}
startNum = startNum - find +1;
int x= 1, y = find;
while(true) {
if(startNum == num)
break;
x++;
y--;
startNum++;
}
//System.out.println(num+"의 좌표 : ("+x+","+y+")");
queue.offer(new int[] {x,y});
}
}
규칙? 찾아서 풀어땅
'알고리즘 > SWExpert' 카테고리의 다른 글
[JAVA]SWEA_7236_저수지의 물의 총 깊이 구하기 (0) | 2021.02.26 |
---|---|
[JAVA]SWExpert_1247_최적경로 (0) | 2021.02.18 |
[JAVA]SWExpert_6808_규영이와 인영이의 카드게임 (0) | 2021.02.15 |
[JAVA]SWEA_1974_스도쿠 검증 (0) | 2021.02.10 |
[JAVA]SWExpert_9229_한빈이와 Spot Mart (0) | 2021.02.10 |