View Code of Problem 106

#include "iostream"
#include "algorithm"
#include "math.h"
#include "stdio.h"
using namespace std;

int  main(){
    double x1,y1,x2,y2,r;
    while (scanf("%lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&r)!=EOF){
        double dis=sqrt(pow(abs(x1-x2),2)+pow(abs(y1-y2),2));
        if(dis==2*r){
            cout<<"相切"<<endl;
        }
        else if(dis==0){
            cout<<"重合"<<endl;
        }
        else if(dis>2*r){
            cout<<"相离"<<endl;
        }
        else{
            dis=dis*1.0/2;
            double t=sqrt(pow(r,2)-pow(dis,2));
            double s=dis*t;
            double j1=acos(dis*1.0/r)*2*180*1.0/M_PI;
            double s1=j1*1.0/360*M_PI*r*r;
            double s2=(s1-s)*2;
          
            printf("相交 %.2f\n",s2);
        }
    }
}

Double click to view unformatted code.


Back to problem 106