SSAFY/SWEA

[SWEA] 11285 : 다트게임

믕비 2023. 5. 12. 18:39
반응형

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AXZuaLsqz9wDFAST&categoryId=AXZuaLsqz9wDFAST&categoryType=CODE&problemTitle=&orderBy=RECOMMEND_COUNT&selectCodeLang=JAVA&select-1=3&pageSize=10&pageIndex=4 

 

SW Expert Academy

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

swexpertacademy.com

정답률이 낮아서 쫄았는데 옛날에 잦던 오류 때문에 정답률이 낮았던 문제인 것 같다.

쉽게 풀었음.

주어진 좌표로 원점에서의 길이를 구한 후 그것보다 크거나 같은 반지름의 점수를 더해줬다.

 

내 코드

메모리 : 93804 KB

시간 : 426 ms

코드길이 : 1102 B

 

[내 코드]

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Solution {
	static int[] radius = {20, 40, 60, 80, 100, 120, 140, 160, 180, 200};
	static int[] grade = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		StringTokenizer st;
		
		int T = Integer.parseInt(br.readLine());
		for(int t = 1; t <= T; t++) {
			sb.append('#').append(t).append(' ');
			int N = Integer.parseInt(br.readLine());
			int result = 0;
			for(int n = 0; n < N; n++) {
				st = new StringTokenizer(br.readLine());
				int x = Integer.parseInt(st.nextToken());
				int y = Integer.parseInt(st.nextToken());
				result += score(x, y);
			}
			sb.append(result).append('\n');
		}
		System.out.print(sb);
	}
	static int score(int x, int y) {
		double length = Math.sqrt(x*x + y*y);
		for(int i = 0; i < 10; i++) {
			if(radius[i] >= length)
				return grade[i];
		}
		return 0;
	}
}
반응형