상세 컨텐츠

본문 제목

백준 1358번

백준 알고리즘 풀이

by 발발개발 2022. 5. 19. 14:33

본문

원본 : https://www.acmicpc.net/problem/1358

 

1358번: 하키

첫째 줄에 수 W H X Y P가 주어진다. P는 선수의 수이다. W와 H는 100보다 작거나 같은 자연수이고, H는 짝수이다. X와 Y는 절댓값이 100보다 작거나 같은 정수이다. P는 최대 50인 자연수이다. 둘째 줄부

www.acmicpc.net

 

풀이

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

public class Main {
    private static final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    private static final StringBuilder stringBuilder = new StringBuilder();

    public static void main(String[] args) throws Exception {
        StringTokenizer stringTokenizer = new StringTokenizer(bufferedReader.readLine());
        int w = Integer.parseInt(stringTokenizer.nextToken());
        int h = Integer.parseInt(stringTokenizer.nextToken());
        int x = Integer.parseInt(stringTokenizer.nextToken());
        int y = Integer.parseInt(stringTokenizer.nextToken());
        int p = Integer.parseInt(stringTokenizer.nextToken());
        int count = 0;

        for (int i = 0; i < p; i++) {
            stringTokenizer = new StringTokenizer(bufferedReader.readLine());
            int personX = Integer.parseInt(stringTokenizer.nextToken());
            int personY = Integer.parseInt(stringTokenizer.nextToken());

            double powY = Math.pow((y + h / 2.0) - personY, 2);

            if (personX >= x && personX <= x + w && personY >= y && personY <= y + h) {
                count++;
            } else if (Math.sqrt(Math.pow(x - personX, 2) + powY) <= (h / 2.0)) {
                count++;
            } else if (Math.sqrt(Math.pow(x + w - personX, 2) + powY) <= (h / 2.0)) {
                count++;
            }
        }

        System.out.println(stringBuilder.append(count));
    }
}

'백준 알고리즘 풀이' 카테고리의 다른 글

백준 2559번  (0) 2022.05.19
백준 11659번  (0) 2022.05.19
백준 1004번  (0) 2022.05.19
백준 2477번  (0) 2022.05.19
백준 3034번  (0) 2022.05.19

관련글 더보기

댓글 영역