3일차

    코드

    #include <stdio.h>
    void swap(int a, int b){
    	int t;
    	t = a;
    	a = b;
    	b = t;
    }
    
    int main(){
    	int x1, x2, y1, y2, r1, r2;
    	int T, distinct, numIntersection = 0;
        
    	scanf("%d", &T);
        
    	for(int i = 0; i < T; i++){
    		scanf("%d %d %d %d %d %d", &x1, &y1, &r1, &x2, &y2, &r2);
            
    		distinct = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
            
    		if(r1 < r2){
    			swap(r1, r2);
    		}
            
    		if(distinct == (r1 + r2) * (r1 + r2)){
    			numIntersection = 1; // 외접
                
    		}else if((r1 - r2) * (r1 - r2) < distinct && distinct < (r1 + r2) * (r1 + r2)){
    			numIntersection = 2; // 두점에서 만난다.
                
    		}else if(r1 == r2 && distinct == 0){
    			numIntersection = -1; //합동 (위치의 개수 무한대)
                
    		}else if(distinct > (r1 + r2) * (r1 + r2) ){
    			numIntersection = 0; // 멀어서 만나지 않는다.
                
    		}else if(distinct == (r1 - r2) * (r1 - r2) && distinct != 0){
    			numIntersection = 1; // 내접하는 경우 (이때 distinct == 0 이라면 합동인 경우이다.)
                
            	}else if(distinct < (r1 - r2) * (r1 - r2)){
    			numIntersection = 0;    //한원이 다른원에 포함되어 만나지 않는 경우
    		}
            
    		printf("%d\n", numIntersection);
    	}
    	return 0;
    }

    설명

    문제 그대로 T문제 그대로 케이스 개수 T가 주어지고
    좌표가 주어지고 거리를 구하고
    그 좌표에 따른 위치수를 구하면 된다.

    경우의 수 따지기

    반지금 r2>r1인 경우 스왑을 이용해 바꾸워준다.

    이 후 반지름 r1 > r2 라고 가정 , distinct = 두 원의 중심사이의 거리

    1. 만나지 않는 경우

    - 한원이 다른원에 포함되어 만나지 않는 경우

    distinct < r1 - r2

    - 멀어서 만나지 않는 경우

    distinct > r1 + r2

    2. 한 점에서 만나는 경우(접하는 경우)

    - 외접하는 경우

    distinct = r1 + r2

    - 내접하는 경우 

    r1 - r2 = distinct && distinct != 0 // d가 0이 될 경우 합동이 되어서 교차점이 무수히 많아지게 된다.

    3. 두점에서 만나는 경우

    r1 - r2 < distinct < r1 + r2

    4. 합동인 경우

    r1 = r2 && distinct = 0   

    - 교차점이 무수히 많이 생김

    댓글

    Designed by JB FACTORY