アットウィキロゴ

[aoj]0035

#define X real()
#define Y imag()
 
double tri2s(double xa, double ya, double xb, double yb, double xc, double yc){
     double a, b, c, s;
 
     a = sqrt((xb - xc) * (xb - xc) + (yb - yc) * (yb - yc));
     b = sqrt((xa - xc) * (xa - xc) + (ya - yc) * (ya - yc));
     c = sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));
 
     s = (a+b+c) / 2;
 
	 cout << sqrt(s * (s - a) * (s - b) * (s - c)) << endl;
 
     return sqrt(s * (s - a) * (s - b) * (s - c));
}
 
double p2deg(double xa, double ya, double xb, double yb, double xc, double yc){
  double a, b, c, s, cos;
 
     a = sqrt((xb - xc) * (xb - xc) + (yb - yc) * (yb - yc));
     b = sqrt((xa - xc) * (xa - xc) + (ya - yc) * (ya - yc));
     c = sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));
 
	 cos = (b * b + c * c - a * a) / 2 * b * c;
 
	 return acos(cos);
 
}
 
// 直線p1,p2と線分p3,p4の交差判定
// (n < 0)<=>交差 , (n == 0)<=>直線上, (n > 0)<=>交差していない  
double isIntersect(P p1, P p2, P p3, P p4){  
    return ( (p1.X-p2.X)*(p3.Y-p1.Y) + (p1.Y-p2.Y)*(p1.X-p3.X)) * ((p1.X-p2.X)*(p4.Y-p1.Y) + (p1.Y-p2.Y)*(p1.X-p4.X));  
}
 
int main(void){
     double x[4], y[4];
     double sq;
     double tri[4];
     bool isok = true;
 
     while(cin >> x[0]){
          cin.ignore(); cin >> y[0];
          cin.ignore(); cin >> x[1]; cin.ignore(); cin >> y[1];
          cin.ignore(); cin >> x[2]; cin.ignore(); cin >> y[2];
          cin.ignore(); cin >> x[3]; cin.ignore(); cin >> y[3];
 
		  P a(x[0], y[0]);
		  P b(x[1], y[1]);
		  P c(x[2], y[2]);
		  P d(x[3], y[3]);
		  /*
          sq = tri2s(x[0], y[0], x[1], y[1], x[2], y[2]) + tri2s(x[0],y[0],x[2],y[2],x[3],y[3]);
 
          tri[0] = tri2s(x[0], y[0], x[1], y[1], x[2], y[2]);
          tri[1] = tri2s(x[0], y[0], x[1], y[1], x[3], y[3]);
          tri[2] = tri2s(x[0], y[0], x[2], y[2], x[3], y[3]);
          tri[3] = tri2s(x[1], y[1], x[2], y[3], x[3], y[3]);
 
          for(int i=0;i<4;i++){
               if(tri[i] > sq) isok = false;
          }
          if(tri2s(x[0],y[0],x[1],y[1],x[2],y[2]) + tri2s(x[0],y[0],x[2],y[2],x[3],y[3]) ==
			 tri2s(x[0],y[0],x[1],y[1],x[3],y[3]) + tri2s(x[2],y[2],x[1],y[1],x[3],y[3]) ){
               cout << "YES" << endl;
          }else{
               cout << "NO" << endl;
          }
          isok = true;
		  */
 
		  if( isIntersect(a,c,b,d) > 0.0 || isIntersect(b,d,a,c) > 0.0 ){
			cout << "NO" << endl;
		  }else{
			cout << "YES" << endl;
		  }
	 }
	 return 0;
}
最終更新:2011年06月16日 23:31
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。