본문 바로가기
Algorithm/Baekjoon

Baekjoon 3412 Darts JAVA

by Hunveloper 2022. 3. 22.
728x90
 

3412번: Darts

Consider a game in which darts are thrown at a board. The board is formed by 10 circles with radii 20, 40, 60, 80, 100, 120, 140, 160, 180, and 200 (measured in millimeters), centered at the origin. Each throw is evaluated depending on where the dart hits

www.acmicpc.net

문제

Consider a game in which darts are thrown at a board. The board is formed by 10 circles with radii 20, 40, 60, 80, 100, 120, 140, 160, 180, and 200 (measured in millimeters), centered at the origin. Each throw is evaluated depending on where the dart hits the board. The score is p points (p ∈ {1, 2, ... , 10}) if the smallest circle enclosing or passing through the hit point is the one with radius 20 · (11 − p). No points are awarded for a throw that misses the largest circle.

Your task is to compute the total score of a series of n throws.

입력

The first line of the input contains the number of test cases T. The descriptions of the test cases follow:

Each test case starts with a line containing the number of throws n (1 ≤ n ≤ 106). Each of the next n lines contains two integers x and y (−200 ≤ x, y ≤ 200) separated by a space—the coordinates of the point hit by a throw.

출력

Print the answers to the test cases in the order in which they appear in the input. For each test case print a single line containing one integer—the sum of the scores of all n throws.

코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		int tc=Integer.parseInt(br.readLine());
		for(int t=0;t<tc;t++) {
			int n=Integer.parseInt(br.readLine()), ans=0;
			for(int i=0;i<n;i++)
			{
				StringTokenizer st= new StringTokenizer(br.readLine());
				int a=Integer.parseInt(st.nextToken()), b=Integer.parseInt(st.nextToken());
				double r = Math.sqrt(a*a+b*b);
				for(int j=1;j<=10;j++) {
					if(r<=20*j) {
						ans+=11-j;
						break;
					}
				}
			}
			bw.write(ans+"\n");
		}
		bw.close();
	}
}

 

728x90
728x90

'Algorithm > Baekjoon' 카테고리의 다른 글

Baekjoon 13909 창문 닫기 JAVA  (0) 2022.03.24
Baekjoon 24383 НУЛИ JAVA  (0) 2022.03.22
Baekjoon 17626 Four Squares JAVA  (0) 2022.03.21
Baekjoon 9095 1, 2, 3 더하기 JAVA  (0) 2022.03.20
Baekjoon 13549 숨바꼭질 3 JAVA  (0) 2022.03.20

댓글