待解决问题集锦

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=77223#problem/E

只满足锐角三角形和直角三角形:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#define INF 0x3f3f3f3f
using namespace std;
int main (){
    int n;
    cin>>n;
    int Coun=1;
    while(n--){
        double x[3],y[3],X,Y;
        for(int i=0;i<3;i++) cin>>x[i]>>y[i];
        cin>>X>>Y;
        printf("Case #%d: \n",Coun);
        Coun++;
        double k1,k2,b1,b2,tx,ty;
        
       if(y[0]==y[1])
          k1=1.0e100,b1=(x[0]+x[1])/2;
       else{
           k1=-1/((y[0]-y[1])/(x[0]-x[1]));
           tx=(x[0]+x[1])/2,ty=(y[0]+y[1])/2;
           b1=ty-k1*tx;
       }


       if(y[0]==y[2])
           k2=1.0e100,b2=(x[0]+x[2])/2;
        else{
           k2=-1/((y[0]-y[2])/(x[0]-x[2]));
           tx=(x[0]+x[2])/2,ty=(y[0]+y[2])/2;
           b2=ty-k2*tx;
       }

       cout<<k1<<" "<<b1<<" "<<k2<<" "<<b2<<endl;
       if(k1!=1.0e100&&k2!=1.0e100){
            if(k1==0&&k2==0){
               double  maxx=max(x[0],x[1]);
                maxx=max(maxx,x[2]);
               double  minn=max(x[0],x[1]);
                minn=max(minn,x[2]);
                ty=y[0],tx=(maxx-minn)/2;
            }
            else{
              tx=(b2-b1)/(k1-k2);
              ty=((b1*k2)-(b2*k1))/(k2-k1);
            }
       }
       else if(k1==1.0e100&&k2==1.0e100){
               double maxy=max(y[0],y[1]);
                maxy=max(maxy,y[2]);
               double minn=max(y[0],y[1]);
                minn=max(minn,y[2]);
                ty=y[0],tx=(maxy-minn)/2;
       }
       else if(k1==1.0e100){
        tx=b1;
        ty=k2*tx+b2;
       }
       else if(k2==1.0e100){
        tx=b2;
        ty=k1*tx+b1;
       }
        cout<<tx<<"  "<<ty<<endl;
       string str=sqrt((tx-X)*(tx-X)+(ty-Y)*(ty-Y)) > sqrt((tx-x[0])*(tx-x[0])+(ty-y[0])*(ty-y[0]))? "Safe" :"Danger";
       cout<<str<<endl;
    }
    return 0;
}
需利用三角关系进行判断:

你可能感兴趣的:(待解决问题集锦)