본문 바로가기
Programming/BOJ

BOJ #1002 Turret.

by 작은별하나 2019. 12. 29.

It seems that this problem was first solved after joining the Baekjun algorithm.

An intellectual asked a question of the Baekjun algorithm, and I remember joining the Baekjun algorithm to answer it, and then solved some problems.

 

Turret



At that time, I was attending Yonsei University, so I registered as Yonsei University, but it is already a few years ago.

Since I had been used to the Euler project for quite some time, few sites with actual scoring servers such as Baekjun had been restarted recently.

 

The percentage of correct answers in this question is quite low at 19%, which seems to be due to the difficulty of explaining the problem rather than the difficulty of the problem. The difficulty level set by the solvers is Silver IV.

 

https://www.acmicpc.net/problem/1002

 

1002번: 터렛

각 테스트 케이스마다 류재명이 있을 수 있는 위치의 수를 출력한다. 만약 류재명이 있을 수 있는 위치의 개수가 무한대일 경우에는 -1을 출력한다.

www.acmicpc.net

The problem is to write a program that gives two points, draws a circle around each of those points, and calculates the number of intersections.

If you do this, the problem will be very simple, but the Baekjun site often feels like a question for fun and someone wants to be wrong. There is a dislike because of it.



Two circles can be:

The two circles do not meet completely apart from each other, the two circles have no intersection in the containment relationship, the two circles have two intersections, the two circles are in contact (internal or external), and the two circles are completely This is a case of overlap. You can program these cases. Since all coordinates and radii are integers, it would be nice to try to solve the problem without making real calculations possible.

 

Source is here.

//------------------------------------------------------------------------------
//  baekjoon #1002 - Turret
//    - by Aubrey Choi
//    - created at 2015-02-02
//------------------------------------------------------------------------------
#include <stdio.h>

int main()
{
    int n;
    int x1, y1, x2, y2, r1, r2;

    scanf("%d", &n);

    while( n-- )
    {
        scanf("%d%d%d%d%d%d", &x1, &y1, &r1, &x2, &y2, &r2);
        int d = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
        if( d == 0 )
        {
            if( r1 == r2 ) printf("-1\n");
            else printf("0\n");
        }
        else if( d < r1*r1 || d < r2*r2 )
        {
            int c = (r1-r2)*(r1-r2);
            if( c == d ) printf("1\n");
            else if( c > d ) printf("0\n");
            else printf("2\n");
        }
        else
        {
            int c = (r1+r2)*(r1+r2);
            if( c == d ) printf("1\n");
            else if( c < d ) printf("0\n");
            else printf("2\n");
        }
    }
}

 

'Programming > BOJ' 카테고리의 다른 글

BOJ #1007 Vector Matching(Mathematics)  (0) 2020.01.26
BOJ #1005 ACM Craft  (0) 2020.01.02
BOJ #1003 Fibonacci  (0) 2019.12.30

댓글