text
stringlengths
49
983k
#include<cstdio> #define EPS 1e-9 #define pb(a) push_back(a); #define ID_CCW 0 #define ID_CW 1 #define ID_GO 2 #define ID_BACK 3 using namespace std; class Point{ public: double x,y; Point(){} Point(double xx,double yy) : x(xx),y(yy){} }; Point &operator -=(Point &a,const Point &b) { a.x-=b.x; a.y-=b.y; return a; } double dot(const Point &a,const Point &b) { return a.x*b.x+a.y*b.y; } double cross(const Point &a,const Point &b) { return a.x*b.y-a.y*b.x; } int ccw(const Point &a,Point b,Point c) { b-=a; c-=a; double rotdir=cross(b,c); if(rotdir>EPS) return ID_CCW; if(rotdir<-EPS) return ID_CW; if(dot(b,c)>EPS) return ID_GO; return ID_BACK; } int main() { Point p[4]; while(1){ if(scanf("%lf,%lf",&p[0].x,&p[0].y)==EOF) break; for(int i=1;i<4;i++) scanf(",%lf,%lf",&p[i].x,&p[i].y); bool b1=true; for(int i=0;i<4;i++) if(ccw(p[i],p[(i+1)%4],p[(i+2)%4])!=ID_CCW) b1=false; bool b2=true; for(int i=0;i<4;i++) if(ccw(p[i],p[(i+1)%4],p[(i+2)%4])!=ID_CW) b2=false; puts(b1||b2?"YES":"NO"); } return 0; }
#include <complex> #include <cstdio> #include <cmath> using namespace std; // “_À•W‚ðŒ^‚Æ‚·‚é typedef complex<double> P; //XYÀ•W #define X real() #define Y imag() // ’¼ü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(){ double xa, xb, xc, xd, ya, yb, yc, yd; while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF ){ P a( xa , ya ); P b( xb , yb ); P c( xc , yc ); P d( xd , yd ); if( isIntersect(a,c,b,d) > 0.0 || isIntersect(b,d,a,c) > 0.0 ){ printf("NO\n"); }else{ printf("YES\n"); } } }
#include <bits/stdc++.h> using namespace std; using point = complex<double>; constexpr double eps = 1e-8; double dot(point a, point b) { return real(conj(a) * b); } double cross(point a, point b) { return imag(conj(a) * b); } int ccw(point a, point b, point c) { b -= a, c -= a; if(cross(b, c) > eps) return 1; if(cross(b, c) < -eps) return -1; if(dot(b, c) < 0) return 2; if(norm(b) < norm(c)) return -2; return 0; } bool isis_ss(point a1, point b1, point a2, point b2) { return ccw(a1, b1, a2) * ccw(a1, b1, b2) <= 0 && ccw(a2, b2, a1) * ccw(a2, b2, b1) <= 0; } int main() { string s; while(cin >> s) { for(auto& c : s) if(c == ',') c = ' '; stringstream ss(s); vector<point> ps; for(int i = 0; i < 4; ++i) { double x, y; ss >> x >> y; ps.emplace_back(x, y); } bool ok = true; for(int i = 0; i < 4; ++i) { ok &= isis_ss(ps[i], ps[(i + 2) % 4], ps[(i + 1) % 4], ps[(i + 3) % 4]); } cout << (ok ? "YES" : "NO") << endl; } }
#include <cstdio> #include <iostream> using namespace std; bool check(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { if (x1!=x2) { double m = (y2-y1)/(x2-x1); if (y3-y1>m*(x3-x1)&&y4-y1<m*(x4-x1)) return true; else if (y3-y1<m*(x3-x1)&&y4-y1>m*(x4-x1)) return true; else return false; } else { if (x3>x1&&x4<x1) return true; else if (x3<x1&&x4>x1) return true; else return false; } } int main() { double xa,ya,xb,yb,xc,yc,xd,yd; while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF) { if (check(xa,ya,xc,yc,xb,yb,xd,yd)&&check(xb,yb,xd,yd,xa,ya,xc,yc)) puts("YES"); else puts("NO"); } }
#include<iostream> #include<cstdio> using namespace std; struct POS{ double x; double y; }; bool cross(POS a, POS b, POS c, POS d); int main(){ POS a,b,c,d; for(;;){ if(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&(a.x),&(a.y),&(b.x),&(b.y),&(c.x),&(c.y),&(d.x),&(d.y)) == EOF) break; if(cross(a,c,b,d) && cross(b,d,a,c)) cout <<"YES"<<endl; else cout<<"NO"<<endl; } return 0; } bool cross(POS a, POS b, POS c, POS d){ POS v,w,u; v.x = a.x-b.x; v.y = a.y-b.y; w.x = c.x-b.x; w.y = c.y-b.y; u.x = d.x-b.x; u.y = d.y-b.y; return (v.x*w.y-v.y*w.x)*(v.x*u.y-v.y*u.x)<0; }
#include <stdio.h> #include <math.h> using namespace std; int main(){ double x1,x2,x3,x4,y1,y2,y3,y4,dist1,dist2,dist3,dist4,dist5,dist6; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF){ dist1 = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)); dist2 = sqrt((x2-x4)*(x2-x4)+(y2-y4)*(y2-y4)); dist3 = fabs((y2-y4)*x1+(x4-x2)*y1+y2*(x2-x4)-x2*(y2-y4))/(sqrt((y2-y4)*(y2-y4)+(x4-x2)*(x4-x2))); dist4 = fabs((y1-y3)*x2+(x3-x1)*y2+y1*(x1-x3)-x1*(y1-y3))/(sqrt((y1-y3)*(y1-y3)+(x3-x1)*(x3-x1))); dist5 = fabs((y2-y4)*x3+(x4-x2)*y3+y2*(x2-x4)-x2*(y2-y4))/(sqrt((y2-y4)*(y2-y4)+(x4-x2)*(x4-x2))); dist6 = fabs((y1-y3)*x4+(x3-x1)*y4+y1*(x1-x3)-x1*(y1-y3))/(sqrt((y1-y3)*(y1-y3)+(x3-x1)*(x3-x1))); if(dist1 < dist3 || dist2 < dist4 || dist1 < dist5 || dist2 < dist6){ printf("NO\n"); }else{ printf("YES\n"); } } return 0; }
#include <iostream> #include <stdio.h> using namespace std; class Vec { public: double x, y; Vec(double x, double y) : x(x), y(y){} Vec(){} Vec operator-(Vec v) { return Vec(x - v.x, y - v.y); } double GetCp(Vec v) { return (x * v.y - y * v.x); } }; bool IsHit(Vec a, Vec b, Vec c, Vec p) { double A = (b - a).GetCp(p - a); double B = (c - b).GetCp(p - b); double C = (a - c).GetCp(p - c); return (A >= 0 && B >= 0 && C >= 0) || (A <= 0 && B <= 0 && C <= 0); } int main() { Vec v[4]; while (true) { for (int i = 0; i < 4; i++) { if (scanf("%lf,", &(v[i].x)) == -1) return 0; if (scanf("%lf,", &(v[i].y)) == -1) return 0; } if (IsHit(v[0], v[1], v[2], v[3]) || IsHit(v[3], v[0], v[1], v[2]) || IsHit(v[2], v[3], v[0], v[1]) || IsHit(v[1], v[2], v[3], v[0])) { cout << "NO" << endl; } else { cout << "YES" << endl; } } return 0; }
#include<cstdio> #include<cmath> #include <stdlib.h> float spase(float a,float b,float c){ return sqrt((a+b+c)*(b-a+c)*(a-b+c)*(a+b-c)); } int main(){ float a,b,c,d,e,f,g,h,AB,BC,CD,DA,AC,BD,abc,bcd,cda,dab; while( scanf("%f,%f,%f,%f,%f,%f,%f,%f",&a,&b,&c,&d,&e,&f,&g,&h) != EOF ){ AB=sqrt((a-c)*(a-c)+(b-d)*(b-d)); BC=sqrt((c-e)*(c-e)+(d-f)*(d-f)); CD=sqrt((e-g)*(e-g)+(f-h)*(f-h)); DA=sqrt((g-a)*(g-a)+(h-b)*(h-b)); AC=sqrt((a-e)*(a-e)+(b-f)*(b-f)); BD=sqrt((c-g)*(c-g)+(d-h)*(d-h)); abc=((a-c)*(c-e)+(b-d)*(d-f))/AB/BC; bcd=((c-e)*(e-g)+(d-f)*(f-h))/BC/CD; cda=((e-g)*(g-a)+(f-h)*(h-b))/CD/DA; dab=((g-a)*(a-c)+(h-b)*(b-d))/DA/AB; //printf("%f %f %f %f\n",abc,bcd,cda,dab); //printf("%f %f %f %f\n",acos(abc),acos(bcd),acos(cda),acos(dab)); abc=acos(abc)+acos(bcd)+acos(cda)+acos(dab); //printf("%f %f %f %f\n",abc,2*M_PI,spase(AB,BC,AC)+spase(CD,DA,AC),spase(DA,AB,BD)+spase(CD,BC,BD)); //printf("%d %d\n",abs(abc-2*M_PI)<0.0001,abs(spase(AB,BC,AC)+spase(CD,DA,AC)-spase(DA,AB,BD)-spase(CD,BC,BD))<0.0001); if(((abs(abc-2*M_PI)<0.0001))&&(abs(spase(AB,BC,AC)+spase(CD,DA,AC)-spase(DA,AB,BD)-spase(CD,BC,BD))<0.0001)){ printf("YES\n"); } else{ printf("NO\n"); } } return 0; }
#include <bits/stdc++.h> #define PI 3.14159265358979 using namespace std; double f(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4) { return ((x1-x2)*(y3-y1)+(y1-y2)*(x1-x3))*((x1-x2)*(y4-y1)+(y1-y2)*(x1-x4)); } int main() { double x[4],y[4]; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])!=EOF) { if(f(x[0],y[0],x[2],y[2],x[1],y[1],x[3],y[3])>0 || f(x[1],y[1],x[3],y[3],x[0],y[0],x[2],y[2])>0)cout << "NO" << endl; else cout << "YES" << endl; } return 0; }
#include <complex> #include <stdio.h> #include <math.h> using namespace std; // “_À•W‚ðŒ^‚Æ‚·‚é typedef complex<double> P; //XYÀ•W #define X real() #define Y imag() // ’¼ü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(){ double xa, xb, xc, xd, ya, yb, yc, yd; while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF ){ P a( xa , ya ); P b( xb , yb ); P c( xc , yc ); P d( xd , yd ); if( isIntersect(a,c,b,d) > 0.0 || isIntersect(b,d,a,c) > 0.0 ){ printf("NO\n"); }else{ printf("YES\n"); } } return 0; }
#include <iostream> #include <utility> #include <cstdio> #include <cmath> using namespace std; typedef struct{ float x,y; } P; bool judge(P p1,P p2,P p3,P px){ float s,a,b,c; s=0.5*abs((p1.x-p3.x)*(p2.y-p3.y)-(p2.x-p3.x)*(p1.y-p3.y)); a=0.5*abs((p1.x-px.x)*(p2.y-px.y)-(p2.x-px.x)*(p1.y-px.y)); b=0.5*abs((p2.x-px.x)*(p3.y-px.y)-(p3.x-px.x)*(p2.y-px.y)); c=0.5*abs((p3.x-px.x)*(p1.y-px.y)-(p1.x-px.x)*(p3.y-px.y)); if(s==a+b+c||(s+0.001<=a+b+c&&s-0.001>=a+b+c)){ return true; } return false; } int main(void){ P p[4]; int i; bool flag; while(true){ flag=true; for(i=0;i<4;i++){ if(scanf("%f,%f,",&p[i].x,&p[i].y)==EOF)return 0; } if(judge(p[0],p[1],p[2],p[3])==false){ if(judge(p[1],p[2],p[3],p[0])==false){ if(judge(p[2],p[3],p[0],p[1])==false){ if(judge(p[3],p[0],p[1],p[2])==false){ cout<<"YES"<<endl; flag=false; } } } } if(flag){ cout<<"NO"<<endl; } } }
#include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<cstdio> #include<climits> #include<cmath> #include<cstring> #include<string> #include<complex> #include<map> #define f first #define s second #define mp make_pair #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++) #define ALL(c) (c).begin(), (c).end() #define EPS (1e-10) using namespace std; typedef unsigned int uint; typedef long long ll; typedef complex<double> P; int main(){ double x[6]; double y[6]; while(2==scanf("%lf,%lf,",&x[1],&y[1])){ REP(i,3) scanf("%lf,%lf,",&x[i+2],&y[i+2]); x[5] = x[1]; x[0] = x[4]; y[5] = y[1]; y[0] = y[4]; int ans = 0; REP(i,4){ double dx1 = x[i+1] - x[i]; double dx2 = x[i+2] - x[i+1]; double dy1 = y[i+1] - y[i]; double dy2 = y[i+2] - y[i+1]; if(dx1 * dy2 < dx2 * dy1) ans++; else ans--; } if(ans == 4 || ans == -4) ans = 1; else ans = 0; puts(ans?"YES":"NO"); } return 0; }
#include <set> #include <map> #include <list> #include <queue> #include <stack> #include <cmath> #include <ctype.h> #include <ctime> #include <cstdio> #include <vector> #include <string> #include <bitset> #include <cctype> #include <cstdlib> #include <cstring> #include <utility> #include <numeric> #include <complex> #include <sstream> #include <fstream> #include <iomanip> #include <cassert> #include <iostream> #include <iterator> #include <algorithm> using namespace std; #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define lengthof(x) (sizeof(x) / sizeof(*(x))) #define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value)) template <typename T> void FILL_(void * ptr, size_t size, T value){ std::fill((T*)ptr, (T*)ptr+size, value); } //4方向ベクトル→↑←↓ int dx[] ={1,0,-1,0}; int dy[] ={0,-1,0,1}; int main() { double xa,xb,xc,xd,ya,yb,yc,yd; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF){ double td =(xa-xc)*(yd-ya)+(ya-yc)*(xa-xd); double tb =(xa-xc)*(yb-ya)+(ya-yc)*(xa-xb); double ta =(xb-xd)*(ya-yb)+(yb-yd)*(xb-xa); double tc =(xb-xd)*(yc-yb)+(yb-yd)*(xb-xc); if(td*tb >0.0||ta*tc>0.0) cout <<"NO"<<endl; else cout <<"YES"<<endl; } return 0; }
#include <iostream> #include <cstdio> class Point{ public: Point(); Point(double _x, double _y); double x, y; }; Point::Point() : x(0), y(0){} Point::Point(double _x, double _y) : x(_x), y(_y){} class Vector{ //private: public: Vector(); Vector(double _x, double _y); Vector(Point p1, Point p2); double x, y; }; Vector::Vector() : x(0), y(0){} Vector::Vector(double _x, double _y) : x(_x), y(_y){} Vector::Vector(Point p1, Point p2) : x(p1.x-p2.x), y(p1.y-p2.y){} int extproduct(Vector v1, Vector v2){ return v1.x*v2.y - v1.y*v2.x; } int main(){ Point ps[4]; while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &ps[0].x, &ps[0].y, &ps[1].x, &ps[1].y, &ps[2].x, &ps[2].y, &ps[3].x, &ps[3].y)){ int res = 0; for(int i=0;i<4;i++){ int count = 0; Vector vs[4]; vs[0] = Vector(ps[(i+1)%4], ps[(i+2)%4]); vs[1] = Vector(ps[(i+2)%4], ps[(i+3)%4]); vs[2] = Vector(ps[(i+1)%4], ps[(i+3)%4]); for(int j=0;j<3;j++){ vs[3] = Vector(ps[(i+j+1)%4], ps[i]); if(extproduct(vs[j], vs[3]) > 0)count++; else count--; } if(count == 3 || count == -3)res++; } if(res == 4)puts("YES"); else puts("NO"); } }
#include<iostream> #include<cstdio> #include<vector> #include<complex> #include<algorithm> #define P complex<double> using namespace std; bool cmp_p(const P& a, const P& b) { return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real(); } double det(P a, P b) { return a.real() * b.imag() - b.real() * a.imag(); } vector<P> graham_scan(P* ps, int n) { sort(ps, ps + n, cmp_p); int k = 0; vector<P> qs(n * 2); for(int i = 0; i < n; i++) { while(k > 1 && det(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0) k--; qs[k++] = ps[i]; } for(int i = n - 2, t = k; i >= 0; i--) { while(k > t && det(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0) k--; qs[k++] = ps[i]; } qs.resize(k - 1); return qs; } P p[4]; double xa, ya, xb, yb, xc, yc, xd, yd; int main() { while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != -1) { p[0] = P(xa, ya); p[1] = P(xb, yb); p[2] = P(xc, yc); p[3] = P(xd, yd); cout << (graham_scan(p, 4).size() == 4 ? "YES" : "NO") << endl; } }
#include <iostream> #include <cmath> using namespace std; struct P{ double x,y; P(){} P(double x,double y):x(x),y(y){} }; bool isIntersecter(P a,P b,P p,P q ){ return ((a.x - b.x)*(p.y - a.y) - (a.y - b.y)*(p.x - a.x))*((a.x - b.x)*(q.y - a.y) - (a.y - b.y)*(q.x - a.x)) > 0; } int main(){ P a[4]; char c; while(cin >> a[0].x){ cin >> c >> a[0].y; for(int i = 1 ; i < 4 ; i++ ) { cin >> c >> a[i].x >> c >> a[i].y; } if(isIntersecter(a[0],a[2],a[1],a[3]) || isIntersecter(a[1],a[3],a[0],a[2])){ cout << "NO" << endl; } else cout << "YES" << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for(int i=0;i<(int)(n);++i) #define rep1(i, n) for(int i=1;i<=(int)(n);++i) #define irep(i, a, n) for(int i=a;i<(int)(n);++i) #define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i) #define rrep1(i, n) for(int i=(int)(n);i>=1;--i) #define allrep(V, v) for(auto&& V:v) #define all(x) (x).begin(),(x).end() typedef long long lint; const int INF=1<<29; const double EPS=1e-9; using namespace std; int main (void) { double xa,ya,xb,yb,xc,yc,xd,yd; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF){ double area1,area2; area1=abs((xa-xb)*(yc-yb)-(ya-yb)*(xc-xb))+abs((xa-xd)*(yc-yd)-(ya-yd)*(xc-xd)); area2=abs((xb-xa)*(yd-ya)-(yb-ya)*(xd-xa))+abs((xb-xc)*(yd-yc)-(yb-yc)*(xd-xc)); cout << (area1==area2 ? "YES" : "NO") << endl; } return 0; }
#include<iostream> #include<cstdio> #include<cmath> using namespace std; int main(){ double dot[5][2],vec[4][2],edge[4],ang[4],all; for(;;){ if(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&dot[0][0],&dot[0][1],&dot[1][0],&dot[1][1],&dot[2][0],&dot[2][1],&dot[3][0],&dot[3][1]) == EOF){break;} dot[4][0] = dot[0][0]; dot[4][1] = dot[0][1]; for(int i=0; i<4; i++){ vec[i][0] = dot[i+1][0]-dot[i][0]; vec[i][1] = dot[i+1][1]-dot[i][1]; edge[i] = sqrt(vec[i][0]*vec[i][0]+vec[i][1]*vec[i][1]); } ang[0] = acos(-(vec[0][0]*vec[3][0]+vec[0][1]*vec[3][1])/(edge[0]*edge[3])); ang[1] = acos(-(vec[1][0]*vec[0][0]+vec[1][1]*vec[0][1])/(edge[1]*edge[0])); ang[2] = acos(-(vec[2][0]*vec[1][0]+vec[2][1]*vec[1][1])/(edge[2]*edge[1])); ang[3] = acos(-(vec[3][0]*vec[2][0]+vec[3][1]*vec[2][1])/(edge[3]*edge[2])); all = ang[0]+ang[1]+ang[2]+ang[3]; if(all < 6.283){cout <<"NO"<<endl;} else{cout <<"YES"<<endl;} } return 0; }
#include <iostream> #include <cstdio> #include <complex> using namespace std; typedef complex<double> P; #define X real() #define Y imag() //’¼üp1p3‚Ɛü•ªp2p4‚ÌŒð·”»’è //1‚‚̐ü•ªp1p3‚ƁA‚»‚ê‚Ɋ܂܂ê‚È‚¢2“_p2,p4‚ɂ‚¢‚āAp1p3‚Æp1p2Ap1p3‚Æp1p4A‚»‚ꂼ‚ê‚ɂ‚¢‚ÄŠOÏ‚ð‹‚ß‚Ä‚»‚ÌÏ‚ðŽæ‚é //ŠOÏ‚̐³•‰‚̓xƒNƒgƒ‹‚̂Ȃ·Šp‚Ìsin‚Ɉ˂é‚̂ŁAp2,p4‚Ì‚»‚ꂼ‚ꂪp1p3‚̍¶‚É‚ ‚é‚©‰E‚É‚ ‚é‚©‚ª‚í‚©‚é //³‚È‚çŒð·‚µ‚Ä‚¢‚È‚¢A•‰‚È‚çŒð·‚µ‚Ä‚¢‚éA0‚Ȃ璼üã double is_intersected(P p1,P p2,P p3,P p4) { return (((p3.X-p1.X)*(p2.Y-p1.Y)-(p3.Y-p1.Y)*(p2.X-p1.X))*((p3.X-p1.X)*(p4.Y-p1.Y)-(p3.Y-p1.Y)*(p4.X-p1.X))); } int main() { double xa,ya,xb,yb,xc,yc,xd,yd; //’¼üAC‚Ɛü•ªBDA‚ ‚é‚¢‚͐ü•ªAC‚Æ’¼üBD‚ªŒð·‚µ‚Ä‚¢‚ê‚ΓʊpŒ` while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF) { P a(xa,ya),b(xb,yb),c(xc,yc),d(xd,yd); if(is_intersected(a,b,c,d)>0.0 || is_intersected(b,a,d,c)>0.0) cout << "NO" << endl; else cout << "YES" << endl; } return 0; }
#include "math.h" #include "stdio.h" #include <algorithm> #include <string> #include <map> #include <iostream> using namespace std; /** Problem0035 : It is Convex? **/ double calcS(double x1, double y1, double x2, double y2, double x3, double y3) { double S, s, ab, bc, ca; ab = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); bc = sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)); ca = sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1)); s = 0.5*(ab+bc+ca); S=sqrt(s*(s-ab)*(s-bc)*(s-ca)); return S; } int main() { double x1, y1, x2, y2, x3, y3, x4, y4; char c; while (1) { cin >> x1 >> c >> y1 >> c >> x2 >> c >> y2 >> c >> x3 >> c >> y3 >> c >> x4 >> c >> y4; if (cin.eof()) break; if (fabs((calcS(x1,y1,x2,y2,x3,y3)+calcS(x1,y1,x4,y4,x3,y3)) - (calcS(x2,y2,x3,y3,x4,y4)+calcS(x2,y2,x1,y1,x4,y4))) <= 0.01) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include<iostream> #include<complex> #include<vector> using namespace std; typedef complex < double > P; typedef vector< P > G; struct L:public vector< P >{ // L:線分 L(const P& a,const P& b){push_back(a);push_back(b);} }; const double EPS = 1e-8; const double INF = 1e12; double cross(const P& a,const P& b){ return imag(conj(a) * b); } double dot(const P& a,const P& b){ return real(conj(a) * b); } int ccw(P a,P b,P c){ b -= a; c -= a; if(cross(b,c) > 0) return 1; if(cross(b,c) < 0) return -1; if(dot(b,c) < 0) return 2; // c--a--b if(norm(b) < norm(c)) return -2; // a--b--c return 0; // a--c--b } bool intersect(const L& s,const L& t){ return ccw(s[0],s[1],t[0]) * ccw(s[0],s[1],t[1]) <= 0 && ccw(t[0],t[1],s[0]) * ccw(t[0],t[1],s[1]) <= 0; } bool isconvex(const G& g){ return intersect(L(g[0],g[2]),L(g[1],g[3])) && intersect(L(g[1],g[3]),L(g[0],g[2])); } int main(){ double x1,y1,x2,y2,x3,y3,x4,y4; char o; while(cin >> x1 >> o >> y1 >> o >> x2 >> o >> y2 >> o >> x3 >> o >> y3 >> o >> x4 >> o >> y4){ G g(4); g[0] = P(x1,y1); g[1] = P(x2,y2); g[2] = P(x3,y3); g[3] = P(x4,y4); cout << (isconvex(g) ? "YES" : "NO") << endl; } }
#include <iostream> #include <cmath> #include <complex> using namespace std; typedef complex<double> C; #define EPS (1e-8) double cross(C a, C b) { return a.real() * b.imag() - a.imag() * b.real(); } const string mes[2] = {"YES", "NO"}; double xa, ya, xb, yb, xc, yc, xd, yd; void solve() { C a(xa, ya), b(xb, yb), c(xc, yc), d(xd, yd); // ABC // BCD // CDA // DAB double scross = cross(a-b,b-c) * cross(b-c,c-d) * cross(c-d,d-a) * cross(d-a,a-b); int res = (scross > EPS) ? 0 : 1 ; cout<<mes[res]<<endl; } int main (int argc, char const* argv[]) { char c; while (cin>>xa>>c>>ya>>c>>xb>>c>>yb>>c>>xc>>c>>yc>>c>>xd>>c>>yd) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int Hekomi(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { double A, B, C; A = (x2 - x1)*(y4 - y1) - (y2 - y1)*(x4 - x1); B = (x3 - x2)*(y4 - y2) - (y3 - y2)*(x4 - x2); C = (x1 - x3)*(y4 - y3) - (y1 - y3)*(x4 - x3); if ((A > 0 && B > 0 && C > 0) || (A < 0 && B < 0 && C < 0)) return 0; else return 1; } int main() { double x1, x2, x3, x4, y1, y2, y3, y4; char a; vector<int> TF; while (cin >> x1 >> a >> y1 >> a >> x2 >> a >> y2 >> a >> x3 >> a >> y3 >> a >> x4 >> a >> y4) { TF.push_back(1); if (Hekomi(x1, y1, x2, y2, x3, y3, x4, y4) == 0) { TF.pop_back(); TF.push_back(0); } if (Hekomi(x1, y1, x2, y2, x4, y4, x3, y3) == 0){ TF.pop_back(); TF.push_back(0); } if (Hekomi(x1, y1, x4, y4, x3, y3, x2, y2) == 0){ TF.pop_back(); TF.push_back(0); } if (Hekomi(x4, y4, x2, y2, x3, y3, x1, y1) == 0){ TF.pop_back(); TF.push_back(0); } } for (int i = 0; i < TF.size(); i++) { if (TF[i])cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <iostream> #include <algorithm> #include <cmath> #define rep(i, n) for(int i = 0; i < n; i++) using namespace std; struct Point { double x, y; Point(double x=0, double y=0) : x(x), y(y) {} Point operator - (Point p) { return Point(x-p.x, y-p.y); } }; typedef Point Vector; double cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; } Point p[4]; bool solve() { double c0 = cross(p[1] - p[0], p[2] - p[0]); for(int i = 1; i < 4; i++) { if(c0 * cross(p[(i+1)%4] - p[i], p[(i+2)%4] - p[i]) < 0.0) return false; } return true; } int main() { while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &p[0].x, &p[0].y, &p[1].x, &p[1].y, &p[2].x, &p[2].y, &p[3].x, &p[3].y) != EOF ) { cout << (solve() ? "YES" : "NO") << endl; } }
#include <cstdio> #include <complex> using namespace std; typedef complex<double> P; int cross(P a, P b) { return imag(conj(a) * b); } int ccw(P a, P b, P c) { b -= a; c -= a; if (cross(b, c) > 0) return +1; // counter clockwise if (cross(b, c) < 0) return -1; // clockwise // if (dot(b, c) < 0) return +2; // c--a--b on line // if (norm(b) < norm(c)) return -2; // a--b--c on line return 0; } int main() { for (;;) { P p[4]; double x, y; if (scanf("%lf,%lf,", &x, &y) == EOF) break; p[0] = P(x, y); scanf("%lf,%lf,", &x, &y); p[1] = P(x, y); scanf("%lf,%lf,", &x, &y); p[2] = P(x, y); scanf("%lf,%lf,", &x, &y); p[3] = P(x, y); int sign = ccw(p[0], p[1], p[2]); if (ccw(p[1], p[2], p[3]) == sign && ccw(p[2], p[3], p[0]) == sign && ccw(p[3], p[0], p[1]) == sign) puts("YES"); else puts("NO"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;++i) typedef complex<double> Point; typedef vector<Point> VP; #define X real() #define Y imag() #define debug(x) cout<<#x<<": "<<x<<endl double cross(Point a, Point b) { return a.X*b.Y - a.Y*b.X; } bool isConvex(VP ps) { int n = ps.size(); vector<bool> ccw(n); rep(i,n) ccw[i] = cross(ps[(i+1)%n]-ps[i], ps[(i+2)%n]-ps[i])>0; rep(i,n-1) if(ccw[i]!=ccw[i+1]) return false; return true; } int main(void){ double xa,ya,xb,yb,xc,yc,xd,yd; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF){ if(isConvex({{xa,ya},{xb,yb},{xc,yc},{xd,yd}})){ cout<<"YES"<<endl; }else cout<<"NO"<<endl; } return 0; }
#include<iostream> using namespace std; #define turn(x1,y1,x2,y2,x3,y3) x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2) int hantei(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy); int main() { int i; double xy[8]; int ans; char a; for(;cin >> xy[0];) { for(i=1;i<8;i++) cin >> a >> xy[i]; ans=1; if(hantei(xy[0],xy[1],xy[2],xy[3],xy[4],xy[5],xy[6],xy[7])==0) ans=0; if(hantei(xy[2],xy[3],xy[4],xy[5],xy[6],xy[7],xy[0],xy[1])==0) ans=0; if(hantei(xy[4],xy[5],xy[6],xy[7],xy[0],xy[1],xy[2],xy[3])==0) ans=0; if(hantei(xy[6],xy[7],xy[0],xy[1],xy[2],xy[3],xy[4],xy[5])==0) ans=0; if(ans==1) printf("YES\n"); else printf("NO\n"); } } int hantei(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy) { if(( turn(ax,ay,bx,by,cx,cy)>0 && turn(dx,dy,ax,ay,bx,by)>0 && turn(dx,dy,bx,by,cx,cy)>0 && turn(dx,dy,cx,cy,ax,ay)>0) ||( turn(ax,ay,bx,by,cx,cy)<0 && turn(dx,dy,ax,ay,bx,by)<0 && turn(dx,dy,bx,by,cx,cy)<0 && turn(dx,dy,cx,cy,ax,ay)<0) ) return 0; else return 1; }
#include <cstdio> using namespace std; int main() { double xa, ya, xb, yb, xc, yc, xd, yd; double vx1, vy1, vx2, vy2; while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) == 8) { vx1 = ya-yc; vy1 = xc-xa; vx2 = yb-yd; vy2 = xd-xb; if ((vx1*(xb-xa)+vy1*(yb-ya))*(vx1*(xd-xa)+vy1*(yd-ya)) > 0 || (vx2*(xa-xb)+vy2*(ya-yb))*(vx2*(xc-xb)+vy2*(yc-yb)) > 0) printf("NO\n"); else printf("YES\n"); } return 0; }
#include <iostream> #include <stdio.h> using namespace std; bool check(double x1, double y1, double x2, double y2, double x3, double y3); int main(void){ double xa,ya,xb,yb,xc,yc,xd,yd; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF){ if(check(xa,ya,xb,yb,xc,yc) && check(xb,yb,xc,yc,xd,yd) && check(xc,yc,xd,yd,xa,ya) && check(xd,yd,xa,ya,xb,yb)){ cout<<"YES"<<endl; } else if(!check(xa,ya,xb,yb,xc,yc) && !check(xb,yb,xc,yc,xd,yd) && !check(xc,yc,xd,yd,xa,ya) && !check(xd,yd,xa,ya,xb,yb)){ cout<<"YES"<<endl; } else{ cout<<"NO"<<endl; } } } bool check(double x1, double y1, double x2, double y2, double x3, double y3){ double z; z=(x1-x2)*(y3-y2)-(x3-x2)*(y1-y2); if(z>0){ return true; } else{ return false; } }
#include<bits/stdc++.h> #define _ ios_base::sync_with_stdio(0);cin.tie(0); #define REP(i,n) for(int i=0;i<(int)(n);i++) using namespace std; typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-8, pi = acos(-1.0); bool eq(ld a, ld b){return (abs(b-a)<eps);} ld dot(Point a, Point b){return real(conj(a)*b);} ld cross(Point a, Point b){ return imag(conj(a)*b);} int ccw(Point a, Point b, Point c){ b-=a;c-=a; if(cross(b,c)>eps) return 1;//countor_crockwise if(cross(b,c)<-eps) return -1;//crockwise if(dot(b,c)<0) return 2;//c,a,b if(norm(b)<norm(c)) return -2;//a,b,c return 0;//a,c,b } int main(){ ld xa,ya,xb,yb,xc,yc,xd,yd; Point a,b,c,d; while(scanf("%Lf,%Lf,%Lf,%Lf,%Lf,%Lf,%Lf,%Lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=-1){ a=Point(xa,ya); b=Point(xb,yb); c=Point(xc,yc); d=Point(xd,yd); int abc = ccw(a,b,c); int bcd = ccw(b,c,d); int cda = ccw(c,d,a); int dab = ccw(d,a,b); if((abc==1&&bcd==1&&cda==1&&dab==1)||(abc==-1&&bcd==-1&&cda==-1&&dab==-1)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } }
#include<iostream> #include<string> #include<sstream> #include<algorithm> #include<cmath> #include<map> #include<set> #include<vector> #include<stack> #include<queue> #include<deque> using namespace std; bool sameside (double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy) { bool result = false; if (ax != bx) { double r = (ay - by) / (ax - bx); double s = ay - r * ax; if ( (r * cx + s - cy) * (r * dx + s - dy) > 0) { result = true; } } else { if ( (cx - ax) * (dx - ax) > 0 ) { result = true; } } return result; } int main() { double ax, ay, bx, by, cx, cy, dx, dy; char c; while(cin >> ax >> c >> ay >> c >> bx >> c >> by >> c >> cx >> c >> cy >> c >> dx >> c >> dy) { if( sameside(ax, ay, cx, cy, bx, by, dx, dy) || sameside(bx, by, dx, dy, ax, ay, cx, cy) ) { cout << "NO" << endl; } else { cout << "YES" << endl; } } return 0; }
#include <iostream> #include <sstream> #include <string> #include <algorithm> using namespace std; const double eps = 1e-12; double x[4], y[4]; void rotate() { double lx = x[3], ly = y[3]; for ( int i = 2; i >= 0; i-- ) x[i+1] = x[i], y[i+1] = y[i]; x[0] = lx, y[0] = ly; } double cross( double x1, double y1, double x2, double y2 ) { return x1 * y2 - y1 * x2; } bool check() { double a = cross( x[1] - x[0], y[1] - y[0], x[3] - x[0], y[3] - y[0] ); double b = cross( x[2] - x[1], y[2] - y[1], x[3] - x[1], y[3] - y[1] ); double c = cross( x[0] - x[2], y[0] - y[2], x[3] - x[2], y[3] - y[2] ); return ( a > 0 && b > 0 && c > 0 ) || ( a < 0 && b < 0 && c < 0 ); } bool solve() { for ( int i = 0; i < 4; i++ ) { if ( check() ) return false; rotate(); } return true; } int main( void ) { string input; while ( cin >> input ) { replace( input.begin(), input.end(), ',', ' ' ); istringstream is(input); for ( int i = 0; i < 4; i++ ) is >> x[i] >> y[i]; cout << ( solve()? "YES" : "NO" ) << endl; } return 0; }
#include<iostream> #include<complex> #include<cstdio> #define EPS 1.0e-10 using namespace std; typedef complex<double> P; P a[4]; double cross(P a, P b) { return (a.real() * b.imag() - a.imag() * b.real()); } int is_intersected_ls(P a1, P a2, P b1, P b2) { return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) && ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS ); } int main(){ double x,y; char c; while(scanf("%lf,%lf",&x,&y)!=EOF){ a[0]=P(x,y); for(int i=1;i<4;i++){ scanf(",%lf,%lf",&x,&y);; a[i]=P(x,y); } if(is_intersected_ls(a[0],a[2],a[1],a[3])) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
#include <iostream> #include <cstdio> using namespace std; class Vector{ public: double x,y; Vector(){} Vector( double dx, double dy ){ x = dx; y = dy; } Vector operator-( const Vector& hoge ){ return Vector( x - hoge.x, y - hoge.y ); } Vector operator-( const Vector& hoge ) const{ return Vector( x - hoge.x, y - hoge.y ); } }; double crossConduct( const Vector& lhs, const Vector& rhs ) { return lhs.x * rhs.y - lhs.y * rhs.x; } double line( const Vector& a, const Vector& b, const Vector& p ) { Vector hoge = b - a; Vector piyo = p - a; return crossConduct( hoge, piyo ); } int main(int argc, char const* argv[]) { Vector A,B,C,D; char comma; while( cin >> A.x >> comma >> A.y >> comma >> B.x >> comma >> B.y >> comma >> C.x >> comma >> C.y >> comma >> D.x >> comma >> D.y ){ double a,b,c,d; a = line( A, B, C ); b = line( B, C, D ); c = line( C, D, A ); d = line( D, A, B ); if( ( a > 0 && b > 0 && c > 0 && d > 0 ) || ( a < 0 && b < 0 && c < 0 && d < 0 ) ) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <iostream> #include <cassert> #include <cmath> #include <complex> using namespace std; typedef complex<double> P; #define EPS (1e-10) #define PI (3.14159265358979323846) #define X(a) ( (a).real() ) #define Y(a) ( (a).imag() ) #define EQ(a,b) ( -EPS<(a)-(b) && (a)-(b)<EPS ) #define EQV(a,b) ( EQ(X(a),X(b)) && EQ(Y(a),Y(b)) ) #define unit(a) ( (a)/abs(a) ) #define normal(a) ( (a)*P(0,1) ) #define dot(a,b) ( X((a)*conj(b)) ) #define cross(a,b) ( Y(conj(a)*(b)) ) int ccw(P a, P b, P c) { b -= a; c -= a; if(cross(b, c) > 0) return +1; // counter clockwise if(cross(b, c) < 0) return -1; // clockwise if(dot(b, c) < 0) return +2; // c--a--b on line if(norm(b) < norm(c)) return -2; // a--b--c on line return 0; } int main() { P p[4]; int a; double x,y; char c; while(cin >> x >> c >> y) { p[0]=P(x,y); for(int i=1; i<4; i++) { cin >> c >> x >> c >> y; p[i]=P(x,y); } a=0; for(int i=0; i<4; i++) { a+=ccw(p[i],p[(i+1)%4],p[(i+2)%4]); } cout << (a==4||a==-4 ? "YES":"NO") << endl; } }
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<bitset> #include<cmath> #include<cstdio> using namespace std; double dis(double xa,double ya,double xb,double yb){ return sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)); } double S(double a,double b,double c){ double s=(a+b+c)/2; return sqrt(s*(s-a)*(s-b)*(s-c)); } bool in(double xa,double ya,double xb, double yb,double xc,double yc,double xp,double yp){ double AB,BC,CA,AP,BP,CP; AB=dis(xa,ya,xb,yb); BC=dis(xb,yb,xc,yc); CA=dis(xc,yc,xa,ya); AP=dis(xa,ya,xp,yp); BP=dis(xb,yb,xp,yp); CP=dis(xc,yc,xp,yp); double ABC,ABP,BCP,CAP; ABC=S(AB,BC,CA);ABP=S(AB,AP,BP); BCP=S(BC,BP,CP);CAP=S(CA,CP,AP); double dif=ABC-ABP-BCP-CAP; if(dif<=0.0001&&dif>=-0.0001)return true; else return false; } int main(){ double x[4],y[4]; while(scanf("%lf,%lf",&x[0],&y[0])!=EOF){ for(int i=1;i<4;i++)scanf(",%lf,%lf",&x[i],&y[i]); bool F=false; for(int i=0;i<4;i++){ int a=(i+1)%4,b=(i+2)%4,c=(i+3)%4; F|=in(x[i],y[i],x[a],y[a],x[b],y[b],x[c],y[c]); } if(!F)cout<<"YES"<<endl; else cout<<"NO"<<endl; } }
#include <cstdio> using namespace std; int side(double a, double b, double c, double d) { return a * d - b * c >= 0 ? 1 : -1; } int main() { double x[8], y[8]; while (scanf("%lf,%lf", x, y) == 2) { for (int i = 1; i < 4; i++) scanf(",%lf,%lf", x+i, y+i); for (int i = 0; i < 4; i++) x[i+4] = x[i]; int s = 0; for (int i = 0; i < 4; i++) s += side(x[i+1]-x[i], y[i+1]-y[i], x[i+2]-x[i+1], y[i+2]-y[i+1]); puts((s == 4 || s == -4) ? "YES" : "NO"); } return 0; }
#include<cstdio> #include<cmath> int main(){ double a[4][2]; double d[4]; bool f = 0; int count; while(1 + scanf("%lf,%lf,", &a[0][0], &a[0][1])){ count = 0; for(int i = 1; i < 4; i++){ scanf("%lf,%lf,", &a[i][0], &a[i][1]); } for(int i = 0; i < 4; i++){ d[i] = atan2(a[i][0] - a[(i+1)%4][0],a[i][1] - a[(i+1)%4][1]); } for(int i = 0; i < 4; i++){ if(0 < sin(d[i] - d[(i+1)%4])){ count++; }else{ count--; } } if(count / 3){ printf("YES\n"); }else{ printf("NO\n"); } } return 0; }
#include<stdio.h> int main(){ double ax,ay,bx,by,cx,cy,dx,dy; while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy)){ if( ((ax-cx)*(by-ay)+(ay-cy)*(ax-bx))* ((ax-cx)*(dy-ay)+(ay-cy)*(ax-dx))<=0&& ((bx-dx)*(ay-by)+(by-dy)*(bx-ax))* ((bx-dx)*(cy-by)+(by-dy)*(bx-cx))<=0)printf("YES\n"); else printf("NO\n"); } }
#include <bits/stdc++.h> using namespace std; #define EPS 1e-10 typedef complex<double> P; double cross(P a, P b) { return (a.real() * b.imag() - a.imag() * b.real()); } bool is_intersect(P a1, P a2, P b1, P b2) { return (cross(a2 - a1, b1 - a1) * cross(a2 - a1, b2 - a1) < EPS) && (cross(b2 - b1, a1 - b1) * cross(b2 - b1, a2 - b1) < EPS); } int main() { double xa, ya, xb, yb, xc, yc, xd, yd; char d; while (cin >> xa >> d >> ya >> d >> xb >> d >> yb >> d >> xc >> d >> yc >> d >> xd >> d >> yd) { P a(xa, ya), b(xb, yb), c(xc, yc), d(xd, yd); if (is_intersect(a, c, b, d)) cout << "YES\n"; else cout << "NO\n"; } }
#include <cstdio> #include <complex> using namespace std; int main() { while (true) { double x[4]; double y[4]; if (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", x+0, y+0, x+1, y+1, x+2, y+2, x+3, y+3) != 8) break; complex<double> c[4]; for (int i=0; i<4; i++) c[i] = complex<double>(x[i], y[i]); int l = 0; int r = 0; for (int i=0; i<4; i++) { complex<double> a = c[(i+2)%4] - c[(i+1)%4]; complex<double> b = c[(i+1)%4] - c[(i+0)%4]; (arg(a/b)>0 ? l : r)++; } puts(l==4 || r==4 ? "YES" : "NO"); } }
#include <iostream> #include <vector> #include <stack> #include <queue> #include <map> #include <bitset> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cmath> #define X first #define Y second #define dis(a, b) (b.X - a) * (b.X - a) + (b.Y - a) * (b.Y - a) using namespace std; double cross(pair<double, double> lineA, pair<double, double> lineB){ return (lineA.X * lineB.Y - lineB.X * lineA.Y) / sqrt(dis(0, lineB)); } int main(){ pair<double, double> pointA, pointB, pointC, pointD; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &pointA.X, &pointA.Y, &pointB.X, &pointB.Y, &pointC.X, &pointC.Y, &pointD.X, &pointD.Y) != EOF){ vector<pair<double, double> > point; point.push_back(pointA); point.push_back(pointB); point.push_back(pointC); point.push_back(pointD); int count = 0; for(int i = 0; i < point.size(); i++){ pair<double, double> lineA(point[(i + 1) % 4].X - point[i].X, point[(i + 1) % 4].Y - point[i].Y); pair<double, double> lineB(point[(i + 2) % 4].X - point[i].X, point[(i + 2) % 4].Y - point[i].Y); cross(lineA, lineB) > 0 ? count++ : count--; } cout << (count == 4 || count == -4 ? "YES" : "NO") << endl; } return 0; }
#include <cstdio> #include <cmath> struct line{ double gr,in; int dir; line(){} line(double gradient,double intercept,int direction){ gr=gradient; in=intercept; dir=direction; } }; struct point{ double x,y; point(){} point(double xx,double yy){ x=xx; y=yy; } }; double x[4],y[4]; line make_line(int i,int j){ if(x[i]==x[j]){ return line(0.0,x[i],1); } line l; l.gr=(y[j]-y[i])/(x[j]-x[i]); l.in=y[i]-x[i]*l.gr; l.dir=0; return l; } point cross(line a,line b){ if(a.dir==1)return point(a.in,b.gr*a.in+b.in); if(b.dir==1)return point(b.in,a.gr*b.in+a.in); point p; p.x=-(b.in-a.in)/(b.gr-a.gr); p.y=a.gr*p.x+a.in; return p; } bool check(line a,int i,int j){ line b=make_line(i,j); point p=cross(a,b); //printf("%d %d %f %f\n",i,j,p.x,p.y); if(b.dir==1){ if((p.y-y[i])*(p.y-y[j])>=0.0)return false; }else{ if((p.x-x[i])*(p.x-x[j])>=0.0)return false; } return true; } int main(void){ while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])){ bool flag=true; line l1=make_line(0,2),l2=make_line(1,3); if(!check(l1,1,3) || !check(l2,0,2))flag=false; printf("%s\n",flag?"YES":"NO"); } return 0; }
#include<iostream> #include<math.h> #define PI 3.14159265358979 using namespace std; double cos(double x1, double y1, double x2, double y2,double x3, double y3) { double xa,xb,ya,yb; xa=x2-x1; ya=y2-y1; xb=x2-x3; yb=y2-y3; return (xa*xb+ya*yb)/(sqrt(xa*xa+ya*ya)*sqrt(xb*xb+yb*yb)); } int main(void) { double xa,ya,xb,yb,xc,yc,xd,yd,theta; char c; while(cin>>xa>>c>>ya>>c>>xb>>c>>yb>>c>>xc>>c>>yc>>c>>xd>>c>>yd) { theta=0; theta+=acos(cos(xa,ya,xb,yb,xc,yc)); theta+=acos(cos(xb,yb,xc,yc,xd,yd)); theta+=acos(cos(xc,yc,xd,yd,xa,ya)); theta+=acos(cos(xd,yd,xa,ya,xb,yb)); if(theta<2*PI) { cout<<"NO"<<endl; } else { cout<<"YES"<<endl; } } }
#include <iostream> using namespace std; int p(double x1, double x2, double x3, double x4) { return x1 * x4 - x2 * x3; } int main() { double x[4], y[4]; while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]) != EOF) { double dt[4]; for (int i = 0; i < 4; i++) { dt[i] = p(x[(i+1)%4]-x[i], y[(i+1)%4]-y[i], x[(i+2)%4]-x[i], y[(i+2)%4]-y[i]); } if ((dt[0] > 0 && dt[1] > 0 && dt[2] > 0 && dt[3] > 0) || (dt[0] < 0 && dt[1] < 0 && dt[2] < 0 && dt[3] < 0)) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
#include <iostream> #include <stdio.h> using namespace std; int main() { double x[4],y[4]; double x1,y1,x2,y2,x3,y3; int i; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])!=EOF) { for (i=0;i<4;i++) { x1=x[(i+2) % 4]-x[i]; y1=y[(i+2) % 4]-y[i]; x2=x[(i+2) % 4]-x[(i+3) % 4]; y2=y[(i+2) % 4]-y[(i+3) % 4]; x3=x[(i+2) % 4]-x[(i+1) % 4]; y3=y[(i+2) % 4]-y[(i+1) % 4]; if ((x1*x2+y1*y2+x1*x3+y1*y3)<=0) { i=10; break; } } if (i<10) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <iostream> #include <cstdio> #include <complex> bool read_data(std::complex<double>* points) { double coords[8]; for (int i = 0; i < 8; ++i) { if (scanf((i==0) ? "%lf" : ",%lf", &coords[i]) != 1) { return false; } } for (int i = 0; i < 4; ++i) { points[i] = std::complex<double>(coords[i*2], coords[i*2+1]); } return true; } int main() { std::complex<double> points[4]; while (read_data(points)) { double imag[4] = {}; for (int i = 0; i < 4; ++i) { imag[i] = ((points[(i+2)%4]-points[(i+1)%4])/(points[i%4]-points[(i+1)%4])).imag(); } if ((imag[0] > 0 && imag[1] > 0 && imag[2] > 0 && imag[3] > 0) || (imag[0] < 0 && imag[1] < 0 && imag[2] < 0 && imag[3] < 0)) { std::cout << "YES\n"; } else { std::cout << "NO\n"; } } return 0; }
#include <iostream> #include <cstdio> #include <complex> #include <cmath> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define EPS (1e-8) typedef complex<double> p; #define EQ(a,b) (abs((a)-(b)) < EPS) #define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) ) double cross(p a, p b) { return ( a.real() * b.imag() - a.imag() * b.real() ); } int main() { while (true) { double x[4], y[4]; if (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]) == EOF) break; p point[4]; REP(i, 4) point[i] = p(x[i], y[i]); int cnt[2] = {}; REP(i, 4) { p v[2]; v[0] = point[(i + 1) % 4] - point[i]; v[1] = point[(i + 2) % 4] - point[i]; if (cross(v[0], v[1]) < -EPS) cnt[0]++; else cnt[1]++; } if (cnt[0] == 4 || cnt[1] == 4) puts("YES"); else puts("NO"); } return 0; }
#include <iostream> #include <cstdio> #include <cmath> #include <complex> using namespace std; typedef complex<double> P; #define x real() #define y imag() 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(){ double xa,ya,xb,yb,xc,yc,xd,yd; char e; while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF ){ P a(xa , ya); P b(xb , yb); P c(xc , yc); P d(xd , yd); if(isIntersect(a,c,b,d) > 0.0 || isIntersect(b,d,a,c) > 0.0){ cout << "NO" <<endl; }else cout << "YES" << endl; } return 0; }
#include <iostream> #include <array> int main() { std::array<double, 4> x; std::array<double, 4> y; char comma; while (std::cin >> x[0] >> comma >> y[0]) { for (std::size_t i = 1; i < 4; ++i) { std::cin >> comma >> x[i] >> comma >> y[i]; } if ((((y[1] - y[0]) * (x[0] - x[2]) - (y[0] - y[2]) * (x[1] - x[0])) * ((y[3] - y[0]) * (x[0] - x[2]) - (y[0] - y[2]) * (x[3] - x[0])) < 0) and (((y[0] - y[1]) * (x[1] - x[3]) - (y[1] - y[3]) * (x[0] - x[1])) * ((y[2] - y[1]) * (x[1] - x[3]) - (y[1] - y[3]) * (x[2] - x[1])) < 0)) { std::cout << "YES" << std::endl; } else { std::cout << "NO" << std::endl; } } return 0; }
#include <iostream> using namespace std; struct point{ double x; double y; }; int ccw(point p0, point p1, point p2){ double dx1 = p1.x - p0.x, dy1 = p1.y - p0.y; double dx2 = p2.x - p0.x, dy2 = p2.y - p0.y; if(dy2 * dx1 > dy1 * dx2) return 1; else return -1; } int main(){ point a, b, c, d; char ch; while(cin >> a.x >> ch >> a.y >> ch >> b.x >> ch >> b.y >> ch >> c.x >> ch >> c.y >> ch >> d.x >> ch >> d.y) { if((ccw(a,c,b) != ccw(a,c,d)) && (ccw(b,d,a) != ccw(b,d,c))){ cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
#include<iostream> #include<complex> #include<vector> using namespace std; typedef complex < double > P; typedef vector< P > G; struct L:public vector< P >{ // L:線分 L(const P& a,const P& b){push_back(a);push_back(b);} }; const double EPS = 1e-8; const double INF = 1e12; double cross(const P& a,const P& b){ return imag(conj(a) * b); } double dot(const P& a,const P& b){ return real(conj(a) * b); } int ccw(P a,P b,P c){ b -= a; c -= a; if(cross(b,c) > 0) return 1; if(cross(b,c) < 0) return -1; if(dot(b,c) < 0) return 2; // c--a--b if(norm(b) < norm(c)) return -2; // a--b--c return 0; // a--c--b } bool intersect(const L& s,const L& t){ return ccw(s[0],s[1],t[0]) * ccw(s[0],s[1],t[1]) <= 0 && ccw(t[0],t[1],s[0]) * ccw(t[0],t[1],s[1]) <= 0; } bool isconvex(const G& g){ return intersect(L(g[0],g[2]),L(g[1],g[3])); } int main(){ double x1,y1,x2,y2,x3,y3,x4,y4; char o; while(cin >> x1 >> o >> y1 >> o >> x2 >> o >> y2 >> o >> x3 >> o >> y3 >> o >> x4 >> o >> y4){ G g(4); g[0] = P(x1,y1); g[1] = P(x2,y2); g[2] = P(x3,y3); g[3] = P(x4,y4); cout << (isconvex(g) ? "YES" : "NO") << endl; } }
#include <iostream> #include <algorithm> using namespace std; int main(){ char trash; double x[4], y[4]; while(cin >> x[0] >> trash >> y[0]){ double a,b,c,d,e,f,t,r; for(int i = 1; i < 4; i++){ cin >> trash >> x[i] >> trash >> y[i]; } a = y[2]-y[0]; b = -x[2]+x[0]; e = -1*(y[0]*(x[2]-x[0])-x[0]*(y[2]-y[0])); c = y[3]-y[1]; d = -x[3]+x[1]; f = -1*(y[1]*(x[3]-x[1])-x[1]*(y[3]-y[1])); t = (e*d-b*f)/(a*d-b*c); r = (a*f-c*e)/(a*d-b*c); if(x[2] < x[0]){ swap(x[0],x[2]); } if(x[3] < x[1]){ swap(x[1],x[3]); } if(y[2] < y[0]){ swap(y[0],y[2]); } if(y[3] < y[1]){ swap(y[1],y[3]); } if((t >= x[0] && t <= x[2]) && (t >= x[1] && t <= x[3]) && (r >= y[0] && r <= y[2]) && (r >= y[1] && r <= y[3])){ cout << "YES" << endl; } else{ cout << "NO" << endl; } } }
//35 #include<iostream> #include<complex> using namespace std; typedef complex<double> P; int main(){ for(;;){ P p[4]; for(int i=0;i<4;i++){ double x,y; if(!((cin>>x).ignore()>>y).ignore())return 0; p[i]=P(x,y); } bool a[2]={}; for(int i=0;i<4;i++){ P c=p[i]-p[(i+1)%4],d=p[(i+1)%4]-p[(i+2)%4]; a[c.real()*d.imag()-c.imag()*d.real()>0]|=true; } cout<<((a[0]&a[1])?"NO":"YES")<<endl; } return 0; }
// 0012 を使い回す #include <fstream> #include <iostream> #include <cmath> #include <vector> #include <queue> #include <utility> #include <algorithm> using namespace std; bool same_side(double x1, double y1, double x2, double y2, double x, double y, double x0, double y0) { return ((y1 - y2) * (x - x2) - (x1 - x2) * (y - y2)) * ((y1 - y2) * (x0 - x2) - (x1 - x2) * (y0 - y2)) >= 0; } bool in_triangle(double x1, double y1, double x2, double y2, double x3, double y3, double xp, double yp) { return same_side(x1,y1,x2,y2,xp,yp,x3,y3) && same_side(x2,y2,x3,y3,xp,yp,x1,y1) && same_side(x3,y3,x1,y1,xp,yp,x2,y2); } int main() { double x[4]; double y[4]; char c,d; while (cin >> x[0] >> c >> y[0]) { for (int i = 1; i < 4; i++) cin >> c >> x[i] >> d >> y[i]; bool res = true; int k[4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) k[j] = (j + i) % 4; if (in_triangle(x[k[0]], y[k[0]], x[k[1]], y[k[1]], x[k[2]], y[k[2]], x[k[3]], y[k[3]])) res = false; } if (res) { cout << "YES" << endl; } else { cout << "NO" << endl; } } }
#include <bits/stdc++.h> using namespace std; constexpr double EPS = 1e-9; double cross(double x1, double y1, double x2, double y2) { return x1 * y2 - y1 * x2; } int ccw(double x1, double y1, double x2, double y2, double x3, double y3) { x2 -= x1; y2 -= y1; x3 -= x1; y3 -= y1; const double t = cross(x2, y2, x3, y3); if(t > EPS) return 1; if(t < -EPS) return -1; return 0; } int main() { double x[4]; double y[4]; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", x, y, x+1, y+1, x+2, y+2, x+3, y+3) == 8) { bool ok = true; const int t = ccw(x[0], y[0], x[2], y[2], x[1], y[1]); for(int i = 1; i < 4; ++i) { const int next = (i + 1) % 4; const int next2 = (i + 2) % 4; if(t != ccw(x[i], y[i], x[next2], y[next2], x[next], y[next])) { ok =false; break; } } puts((ok ? "YES" : "NO")); } return 0; }
#define _USE_MATH_DEFINES #include <iostream> #include <iomanip> #include <algorithm> #include <functional> #include <vector> #include <cstdio> #include <cstring> #include <cmath> #include <cfloat> #include <map> #include <queue> #include <stack> #include <list> #include <string> #include <set> #include <complex> using namespace std; typedef complex<double> P; #define x real() #define y imag() bool isIntersect(P p1,P p2,P p3,P p4){ if((((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)))<0) return true; else return false; } int main(){ double xa,ya,xb,yb,xc,yc,xd,yd; while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)){ P a(xa,ya); P b(xb,yb); P c(xc,yc); P d(xd,yd); if(isIntersect(a,c,b,d)&&isIntersect(b,d,a,c)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } }
#include <bits/stdc++.h> using namespace std; typedef complex<double> P; double cross(P a,P b){ return imag(a*conj(b)); } P in(stringstream &cin){ double x,y; if(cin >> x >> y) return P(x,y); exit(0); } int main(){ string l; while(getline(cin,l)){ for( auto &&c : l ) if( c == ',' ) c = ' '; stringstream ss(l); P p[6]; for(int i = 0 ; i < 4 ; i++) p[i] = in(ss); p[4] = p[0]; p[5] = p[1]; int bit = 0; for(int i = 0 ; i < 4 ; i++){ bit |= 1<<(cross(p[i+1]-p[i],p[i+2]-p[i])>0); } if( bit == 3 ){ cout << "NO" << endl; }else{ cout << "YES" << endl; } } }
#include<iostream> struct Point { double x; double y; }; double Abs(double x) { return x>=0 ? x : -x; } double Square(const Point& P, const Point& Q, const Point& R) { Point A = {Q.x-P.x, Q.y-P.y}; Point B = {R.x-P.x, R.y-P.y}; return Abs(A.x*B.y-A.y*B.x); } bool JudgeS(const Point& P, const Point& Q, const Point R, const Point O)//P,Q,R,Sが四角形になる准に { return (Square(P, Q, R) > Square(O, P, Q) + Square(Q, R, O)); } int main() { Point A, B, C, D; char c; while(std::cin >> A.x >> c >> A.y >> c >> B.x >> c >> B.y >> c >> C.x >> c >> C.y >> c >> D.x >> c >> D.y) { if(JudgeS(A,B,C,D) || JudgeS(B,C,D,A) || JudgeS(C,D,A,B) || JudgeS(D,A,B,C)) { std::cout << "NO\n"; } else { std::cout << "YES\n"; } } }
#include <iostream> #include <cstdio> #include <cmath> #include <complex> using namespace std; typedef complex<double> P; #define x real() #define y imag() 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(){ double xa,ya,xb,yb,xc,yc,xd,yd; char e; while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF ){ P a(xa , ya); P b(xb , yb); P c(xc , yc); P d(xd , yd); if(isIntersect(a,c,b,d) > 0 || isIntersect(b,d,a,c) > 0){ cout << "NO" <<endl; }else cout << "YES" << endl; } return 0; }
#include <iostream> #include <stack> #include <stdio.h> using namespace std; double a,b,c;//ax+by+c=0 double x[4],y[4];//p,1,2,3 void make_line(double x1,double y1,double x2,double y2){ if(x1!=x2&&y1!=y2){ a=(y1-y2)/(x1-x2); b=-1; c=-a*x1+y1; }else if(x1==x2){ a=1; b=0; c=-x1; }else if(y1==y2){ a=0; b=1; c=-y1; } return; } bool check(int p,int q,int r){//whether the point is r side or not make_line(x[p],y[p],x[q],y[q]);//line pq if((a*x[r]+b*y[r]+c)*(a*x[0]+b*y[0]+c)<=0)return false; return true; } int main() { char c; while(cin>>x[1]>>c>>y[1]>>c>>x[2]>>c>>y[2]>>c>>x[3]>>c>>y[3]>>c>>x[0]>>c>>y[0]){ bool ans=true; ans&=check(1,2,3); ans&=check(2,3,1); ans&=!check(3,1,2); printf(ans?"YES\n":"NO\n"); } return 0; }
#include <cstdio> #include <iostream> #include <complex> using namespace std; double cross(complex<double> A, complex<double> B) { return A.real() * B.imag() - A.imag() * B.real(); } int main() { complex<double> p[4]; double x, y; while (scanf("%lf,%lf", &x, &y) == 2) { p[0] = complex<double>(x, y); for (int i = 1; i < 4; i++) { scanf(",%lf,%lf", &x, &y); p[i] = complex<double>(x, y); } if (cross(p[2] - p[0], p[1] - p[2]) * cross(p[2] - p[0], p[3] - p[2]) < 0 && cross(p[3] - p[1], p[0] - p[3]) * cross(p[3] - p[1], p[2] - p[3]) < 0) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
#include<iostream> #include<cstdio> #include<cmath> using namespace std; int main(){ double a[2],b[2],c[2],d[2]; double atob[2],btoc[2],ctod[2],dtoa[2]; double edge_ab,edge_bc,edge_cd,edge_da; double angle_a,angle_b,angle_c,angle_d; for(;;){ if(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a[0],&a[1],&b[0],&b[1],&c[0],&c[1],&d[0],&d[1]) == EOF){break;} atob[0] = b[0]-a[0]; atob[1] = b[1]-a[1]; btoc[0] = c[0]-b[0]; btoc[1] = c[1]-b[1]; ctod[0] = d[0]-c[0]; ctod[1] = d[1]-c[1]; dtoa[0] = a[0]-d[0]; dtoa[1] = a[1]-d[1]; edge_ab = sqrt(atob[0]*atob[0]+atob[1]*atob[1]); edge_bc = sqrt(btoc[0]*btoc[0]+btoc[1]*btoc[1]); edge_cd = sqrt(ctod[0]*ctod[0]+ctod[1]*ctod[1]); edge_da = sqrt(dtoa[0]*dtoa[0]+dtoa[1]*dtoa[1]); angle_a = acos(-(atob[0]*dtoa[0]+atob[1]*dtoa[1])/(edge_ab*edge_da)); angle_b = acos(-(btoc[0]*atob[0]+btoc[1]*atob[1])/(edge_bc*edge_ab)); angle_c = acos(-(ctod[0]*btoc[0]+ctod[1]*btoc[1])/(edge_cd*edge_bc)); angle_d = acos(-(dtoa[0]*ctod[0]+dtoa[1]*ctod[1])/(edge_da*edge_cd)); if(angle_a+angle_b+angle_c+angle_d >6.28318 && angle_a+angle_b+angle_c+angle_d <6.28319){cout <<"YES"<<endl;} else{cout<<"NO"<<endl;} } }
#include <iostream> #include <complex> using namespace std; typedef complex<double> P; double cross(P a, P b) {return (a.real() * b.imag() - a.imag() * b.real());} int main(){ char z; double p,q,r,s,t,u,v,w; P a,b,c,d; while(cin>>p>>z>>q>>z>>r>>z>>s>>z>>t>>z>>u>>z>>v>>z>>w){ a = P(p,q);b = P(r,s);c = P(t,u);d = P(v,w); if ((cross(b-a,c-a)*cross(d-a,c-a))<0&&(cross(a-b,d-b)*cross(c-b,d-b))<0)cout<<"YES"<<endl; else cout << "NO" << endl;} }
//http://www5d.biglobe.ne.jp/~tomoya03/shtml/algorithm/Intersection.htm 参照 #include<cstdio> using namespace std; int main(void){ float xa,ya,xb,yb,xc,yc,xd,yd; float ta,tb,tc,td; while((scanf("%f,%f,%f,%f,%f,%f,%f,%f",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd))!=EOF){ ta=(xb-xd)*(ya-yb)+(yb-yd)*(xb-xa); tb=(xa-xc)*(yb-ya)+(ya-yc)*(xa-xb); tc=(xb-xd)*(yc-yb)+(yb-yd)*(xb-xc); td=(xa-xc)*(yd-ya)+(ya-yc)*(xa-xd); if(ta*tc<0 && tb*td<0) printf("YES\n"); else printf("NO\n"); } return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstring> #include <map> #include <queue> #include <stack> #include <set> #include <functional> #include <sstream> #include <complex> #include <climits> using namespace std; #define REP(i,a,n) for(int i=(a);i<(int)(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define mp make_pair #define all(x) x.begin(),x.end() #define EPS 1e-8 typedef complex<double> P; double cross(P& a, P& b){ return a.real()*b.imag() - a.imag()*b.real(); } bool signeq(double a, double b){ if( a+EPS<0.0 && b+EPS<0.0 ) return true; if( a-EPS>0.0 && b-EPS>0.0 ) return true; return false; } int main(){ double x[4],y[4]; while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",x,y,x+1,y+1,x+2,y+2,x+3,y+3)){ int i; double s; for(i=0; i<4; i++){ P A(x[(i+2)%4],y[(i+2)%4]), B(x[(i+1)%4],y[(i+1)%4]), C(x[i],y[i]); P AB = A-B; P BC = B-C; if( i==0 ){ s = cross(AB,BC); }else{ if( !signeq(s,cross(AB,BC)) ) break; } } puts(i==4?"YES":"NO"); } return 0; }
#include <iostream> #include <cstdio> #include <complex> #include <vector> using namespace std; typedef complex<double> P; #define loop(i,a,b) for(int i=(a); i<(int)(b); i++) #define rep(i,b) loop(i,0,b) int main(){ P ps[4]; double x[4], y[4]; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]) != EOF){ rep(i,4) ps[i] = P(x[i],y[i]); double ts[4]; rep(i,4){ P a = ps[i], b = ps[(i+1)%4], c = ps[(i+2)%4]; a-=b; c-=b; double t = arg(a/c); ts[i]=t; } bool ok = true; rep(i,4){ //cout << ts[i] << endl; if(ts[0]*ts[i]<0) ok = false; } if(ok) puts("YES"); else puts("NO"); } }
#include <iostream> using namespace std; int main(){ double x[4], y[4]; double xa, ya, xb, yb; char c; int checkConvex; int i; while(cin>>x[0]>>c>>y[0]){ for(i=1; i<4; i++) cin>>c>>x[i]>>c>>y[i]; checkConvex=0; for(i=1; i<=4; i++){ xa=x[i-1]-x[i%4]; ya=y[i-1]-y[i%4]; xb=x[(i+1)%4]-x[i%4]; yb=y[(i+1)%4]-y[i%4]; if(xa*yb-ya*xb>0) checkConvex++; else checkConvex--; } if(checkConvex==4 || checkConvex==-4) printf("YES\n"); else printf("NO\n"); } return 0; }
#include <cstdio> #include <complex> #include <iostream> using namespace std; double cross(complex<double> z1, complex<double> z2) { return z1.real() * z2.imag() - z1.imag() * z2.real(); } int main() { double x1, y1, x2, y2, x3, y3, x4, y4; while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4) != EOF) { complex<double> a(x1, y1), b(x2, y2), c(x3, y3), d(x4, y4); double ab, bc, cd, da; ab = cross(b - a, c - b); bc = cross(c - b, d - c); cd = cross(d - c, a - d); da = cross(a - d, b - a); if ((ab > 0 && bc > 0 && cd > 0 && da > 0) || (ab < 0 && bc < 0 && cd < 0 && da < 0)) { cout << "YES"; }else { cout << "NO"; } cout << endl; } return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<cstdio> #include<cstdlib> #include<string> #include<sstream> #include<cmath> #include<numeric> #include<map> #include<stack> #include<queue> #include<list> using namespace std; int inf = 1000000000; bool check(double x1, double y1, double x2, double y2){ return x1 * y2 - y1 * x2 > 0; } int main(void) { vector<double> x(4); vector<double> y(4); while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]) != EOF ){ bool f = true; for(int i=0; i<4; i++){ int j = i + 1; bool a = check(x[i%4]-x[(i+1)%4], y[i%4]-y[(i+1)%4], x[(i+1)%4]-x[(i+2)%4], y[(i+1)%4]-y[(i+2)%4]); bool b = check(x[j%4]-x[(j+1)%4], y[j%4]-y[(j+1)%4], x[(j+1)%4]-x[(j+2)%4], y[(j+1)%4]-y[(j+2)%4]); if( a != b ){ f = false; break; } } cout << ( f ? "YES":"NO") << endl; } return 0; } // EOF
#include <iostream> using namespace std; double outer_product (double* x, double* y, int i) { return (x[i] - x[(i+3)%4]) * (y[i] - y[(i+1)%4]) - (y[(i+3)%4] - y[i]) * (x[(i+1)%4] - x[i]); } int main () { double x[4], y[4]; double z0; bool success; while (cin >> x[0]) { cin.ignore(); cin >> y[0]; for (int i = 1; i <= 3; i++) { cin.ignore(); cin >> x[i]; cin.ignore(); cin >> y[i]; } success = true; z0 = outer_product(x, y, 0); for (int i = 1; i < 4; i++) { if (outer_product(x, y, i) * z0 < 0) { success = false; } } if(success) cout << "YES" << endl; else cout << "NO" << endl; } }
#include<iostream> #include<vector> #include<stdio.h> using namespace std; vector<pair<int,int> >vec; int main(){ double x[4],y[4]; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])!=EOF){ double a[4],b[4]; for(int i=0;i<4;i++){ a[i]=x[(i+1)%4]-x[i]; b[i]=y[(i+1)%4]-y[i]; } int suc=1; for(int i=0;i<4;i++){ if((a[i]*b[(i+1)%4]-b[i]*a[(i+1)%4])*(a[(i+1)%4]*b[(i+2)%4]-b[(i+1)%4]*a[(i+2)%4])<0){ // cout<<(x[i]*y[(i+1)%4]-y[i]*x[(i+1)%4])<<" "<<(x[(i+1)%4]*y[(i+2)%4]-y[(i+1)%4]*x[(i+2)%4])<<endl; suc=0; break; } // cout<<(x[i]*y[(i+1)%4])<<" "<<(y[i]*x[(i+1)%4])<<" "<<(x[(i+1)%4]*y[(i+2)%4])<<" "<<(y[(i+1)%4]*x[(i+2)%4])<<endl; } if(suc) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
#include <cstdio> #include <cmath> double Heron(double,double,double); int main(){ double x[4],y[4]; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])!=EOF){ double l01 = sqrt((x[1]-x[0])*(x[1]-x[0])+(y[1]-y[0])*(y[1]-y[0])); double l02 = sqrt((x[2]-x[0])*(x[2]-x[0])+(y[2]-y[0])*(y[2]-y[0])); double l03 = sqrt((x[3]-x[0])*(x[3]-x[0])+(y[3]-y[0])*(y[3]-y[0])); double l12 = sqrt((x[2]-x[1])*(x[2]-x[1])+(y[2]-y[1])*(y[2]-y[1])); double l13 = sqrt((x[1]-x[3])*(x[1]-x[3])+(y[1]-y[3])*(y[1]-y[3])); double l23 = sqrt((x[3]-x[2])*(x[3]-x[2])+(y[3]-y[2])*(y[3]-y[2])); if(fabs((Heron(l01, l12, l02)+Heron(l02, l23, l03))-(Heron(l13, l01, l03)+Heron(l13, l12, l23)))<1){ printf("YES\n"); } else { printf("NO\n"); } } } double Heron(double a,double b,double c){ double s=(a+b+c)/2; return sqrt(s*(s-a)*(s-b)*(s-c)); }
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <string> #include <map> #include <queue> #include <stack> #include <algorithm> #define rep(i,j) REP((i), 0, (j)) #define REP(i,j,k) for(int i=(j);(i)<(k);++i) #define between(a,x,b) ((a)<=(x)&&(x)<=(b)) using namespace std; typedef struct POINT_tag{ double x, y;}POINT_t; typedef struct LINE_tag{ POINT_t a, b;}LINE_t; int side(POINT_t *p, LINE_t *e){ POINT_t p1 = *p; POINT_t p2 = e->a; POINT_t p3 = e->b; const int n = p1.x * (p2.y - p3.y) + p2.x * (p3.y - p1.y) + p3.x * (p1.y - p2.y); if (n > 0) return 1; else if(n < 0) return -1; else return 0; } int main(){ POINT_t a, b, c, d; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y) != EOF){ LINE_t ac, bd; ac.a = a; ac.b = c; bd.a = b; bd.b = d; if(side(&a, &bd) != side(&c, &bd) && side(&b, &ac) != side(&d, &ac)) puts("YES"); else puts("NO"); } return 0; }
#include <cstdio> #include <cstdlib> #include <cmath> #include <map> #include <utility> #include <set> #include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <queue> #include <cstring> #include <functional> #include <complex> using namespace std; #define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++) #define rep(i,n) REP(i,0,n) // BEGIN CUT HERE #define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++) template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();} // END CUT HERE typedef complex<double> P; double crossP(P a, P b){return a.real()*b.imag() - a.imag()*b.real();} int main(){ int i,j,k,n; double xa,ya,xb,yb,xc,yc,xd,yd; P ab,bc,cd,da; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd) != EOF){ bool f = false; ab = P((xb-xa),(yb-ya)); bc = P((xc-xb),(yc-yb)); cd = P((xd-xc),(yd-yc)); da = P((xa-xd),(ya-yd)); if(crossP(ab,bc) > 0 && crossP(bc,cd) > 0 && crossP(cd,da) > 0 && crossP(da,ab) > 0) f = true; if(crossP(ab,bc) < 0 && crossP(bc,cd) < 0 && crossP(cd,da) < 0 && crossP(da,ab) < 0) f = true; if(f) printf("YES\n"); else printf("NO\n"); } return 0; }
#include <iostream> #include <complex> using namespace std; typedef complex<double> P; #define EPS (1.0e-11) #define EQ(a,b) (abs((a)-(b)) < EPS) #define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) ) double cross(P a, P b) { return (a.real() * b.imag() - a.imag() * b.real()); } int main() { double x[4], y[4]; char comma; while (cin >> x[0] >> comma >> y[0]) { for (int i = 1; i < 4; i++) cin >> comma >> x[i] >> comma >> y[i]; double ck = 1; for (int i = 0; i < 4; i++) { ck *= cross(P(x[(i + 1) % 4] - x[i], y[(i + 1) % 4] - y[i]), P(x[(i + 2) % 4] - x[i], y[(i + 2) % 4] - y[i])); } if (ck > EPS) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <iostream> #include <complex> #include <cmath> using namespace std; typedef complex<double> P; // real -> X // imag -> Y bool isIntersect(P p1, P p2, P p3, P p4){ return ( ((p1.real() - p2.real()) * (p3.imag() - p1.imag()) + (p1.imag() - p2.imag()) * (p1.real() - p3.real())) * ((p1.real() - p2.real()) * (p4.imag() - p1.imag()) + (p1.imag() - p2.imag()) * (p1.real() - p4.real())) ) > 0.0; } int main(){ cin.tie(0); ios::sync_with_stdio(false); double xa, ya, xb, yb, xc, yc, xd, yd; // 0 0 1 0 1 1 0 1 char c0; while(cin >> xa >> c0 >> ya >> c0){ cin >> xb >> c0 >> yb >> c0; cin >> xc >> c0 >> yc >> c0; cin >> xd >> c0 >> yd; P a(xa, ya); P b(xb, yb); P c(xc, yc); P d(xd, yd); cout << ((isIntersect(a, c, b, d) || isIntersect(b, d, a, c)) ? "NO" : "YES") << endl; } return 0; }
#include<iostream> #include<stdio.h> #include<cmath> #include<vector> #include<string> #include<algorithm> using namespace std; int main(){ double xa, ya, xb, yb, xc, yc, xd, yd,s1,s2,s3,s4; while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF) { s1=abs((xc - xa)*(yb - ya) - (xb - xa)*(yc - ya)); s2 = abs((xc - xa)*(yd - ya) - (xd - xa)*(yc - ya)); s3 = abs((xb - xa)*(yd - ya) - (xd - xa)*(yb - ya)); s4 = abs((xb - xc)*(yd - yc) - (xd - xc)*(yb - yc)); if (s1 + s2 == s3 + s4) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
#include <cstdio> #include <complex> using namespace std; typedef complex<double> Point; #define X real() #define Y imag() Point ps[4]; double dot(Point a, Point b) { return (conj(a)*b).X; } double cross(Point a, Point b) { return (conj(a)*b).Y; } bool ccw(Point a, Point b, Point c) { return cross(c-b, a-b) > 0.0; } int main() { while (1) { for (int i=0; i<4; i++) { double x, y; if (scanf("%lf,%lf", &x, &y) != 2) return 0; getchar(); ps[i] = Point(x, y); } bool base = ccw(ps[0], ps[1], ps[2]); bool is_convex = true; for (int i=1; i<4; i++) { is_convex &= (base == ccw(ps[i], ps[(i+1)%4], ps[(i+2)%4])); } if (is_convex) puts("YES"); else puts("NO"); } }
#include <iostream> using namespace std; class Point{ public: double x; double y; }; int isTriangleOutside(Point p1, Point p2, Point p3, Point p4){ double r1,r2,r3; r1 = (p2.x-p1.x)*(p4.y-p1.y) - (p4.x-p1.x)*(p2.y-p1.y); r2 = (p3.x-p2.x)*(p4.y-p2.y) - (p4.x-p2.x)*(p3.y-p2.y); r3 = (p1.x-p3.x)*(p4.y-p3.y) - (p4.x-p3.x)*(p1.y-p3.y); if(r1>0&&r2>0&&r3>0 || r1<0&&r2<0&&r3<0){ return 0; }else{ return 1; } } int main(void){ Point pa,pb,pc,pd; char c; int r1,r2,r3,r4; while(cin>>pa.x>>c>>pa.y>>c>>pb.x>>c>>pb.y>>c>>pc.x>>c>>pc.y>>c>>pd.x>>c>>pd.y){ r1 = isTriangleOutside(pa,pb,pc,pd); r2 = isTriangleOutside(pb,pc,pd,pa); r3 = isTriangleOutside(pc,pd,pa,pb); r4 = isTriangleOutside(pa,pb,pd,pc); if(r1==1 && r2==1 && r3==1 &&r4==1){ cout<<"YES"<<endl; }else{ cout<<"NO"<<endl; } } return 0; }
#include <cstdio> using namespace std; double xa, ya, xb, yb, xc, yc, xd, yd; double n1(double x, double y){ return ((xb-xd)*(y-yb)-(yb-yd)*(x-xb)); } double n2(double x, double y){ return ((xa-xc)*(y-ya)-(ya-yc)*(x-xa)); } int main(){ while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF ){ double f1 = n1(xa, ya) * n1(xc, yc); double f2 = n2(xb, yb) * n2(xd, yd); if( f1 < 0 && f2 < 0 ){ printf("YES\n"); }else{ printf("NO\n"); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,a) FOR(i,0,a) struct Point{ double x,y; Point operator - (const Point a){ Point res; res.x=x-a.x; res.y=y-a.y; return res; } }; typedef Point Vector; double cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x; } Vector v[4]; double c[4]; int main(){ while (1){ if (scanf("%lf,%lf,",&v[0].x,&v[0].y)==EOF) break; FOR(i,1,4){ scanf("%lf,%lf,",&v[i].x,&v[i].y); } bool flg=true; REP(i,4){ c[i]=cross(v[(i+1)%4]-v[i],v[(i+2)%4]-v[(i+1)%4]); } REP(i,4){ if (c[i]*c[(i+1)%4]<0) flg=false; } if (flg){ printf("YES\n"); } else{ printf("NO\n"); } } return 0; }
#include <iostream> #include <algorithm> #include <cassert> #include <cctype> #include <complex> #include <cstdio> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) typedef complex<double> P; char c; double x,y,xx,yy,xxx,yyy,xxxx,yyyy; double cr(P a, P b) { return (a.real() * b.imag() - a.imag() * b.real()); } int main(){ while(cin>>x>>c>>y>>c>>xx>>c>>yy>>c>>xxx>>c>>yyy>>c>>xxxx>>c>>yyyy){ P a=P(x,y),b=P(xx,yy),c=P(xxx,yyy),d=P(xxxx,yyyy); int C=cr(d-a,b-a)>0&&cr(a-b,c-b)>0&&cr(b-c,d-c)>0&&cr(c-d,a-d)>0||cr(d-a,b-a)<0&&cr(a-b,c-b)<0&&cr(b-c,d-c)<0&&cr(c-d,a-d)<0; cout<<(C?"YES":"NO")<<endl; } }
#include <cstdio> using namespace std; int main(){ double x[4], y[4]; double vx, vy, v1x, v1y, v2x, v2y; double s, t; bool convex; while((scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3])) != EOF){ convex = true; for(int i = 0; i < 4; i++){ vx = x[i] - x[(i + 1) % 4]; vy = y[i] - y[(i + 1) % 4]; v1x = x[(i + 2) % 4] - x[(i + 1) % 4]; v1y = y[(i + 2) % 4] - y[(i + 1) % 4]; v2x = x[(i + 3) % 4] - x[(i + 1) % 4]; v2y = y[(i + 3) % 4] - y[(i + 1) % 4]; s = (double)(vx*v2y - vy*v2x) / (v1x*v2y - v1y*v2x); t = (double)(vx*v1y - vy*v1x) / (v2x*v1y - v2y*v1x); if(0 <= s && s <= 1 && 0 <= t && t <= 1){ convex = false; printf("NO\n"); break; } } if(convex){ printf("YES\n"); } } return 0; }
#include <iostream> #include <cmath> #include <vector> using namespace std; typedef pair<double, double> P; double Helon(P a, P b, P c) { double square = 0; double x, y, z; x = sqrt((b.first - a.first) * (b.first - a.first) + (b.second - a.second) * (b.second - a.second)); y = sqrt((c.first - a.first) * (c.first - a.first) + (c.second - a.second) * (c.second - a.second)); z = sqrt((c.first - b.first) * (c.first - b.first) + (c.second - b.second) * (c.second - b.second)); double s = (x + y + z) / 2; square = sqrt(s * (s - x) * (s - y) * (s - z)); return(square); } void solve() { vector<P> Vec(4); while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &Vec[0].first, &Vec[0].second, &Vec[1].first, &Vec[1].second, &Vec[2].first, &Vec[2].second, &Vec[3].first, &Vec[3].second)) { double square1 = 0; square1 += Helon(Vec[0], Vec[1], Vec[2]); square1 += Helon(Vec[0], Vec[2], Vec[3]); double square2 = 0; square2 += Helon(Vec[0], Vec[1], Vec[3]); square2 += Helon(Vec[1], Vec[2], Vec[3]); if(fabs(square1 - square2) < 0.00000000001) { cout << "YES" << endl; } else { cout << "NO" << endl; } } } int main() { solve(); return(0); }
#include <iostream> using namespace std; double check(double ax,double ay, double bx, double by){ return ax*by - ay*bx; } int main(){ double x[4],y[4]; char c; while( cin>>x[0]>>c>>y[0] && c ){ for( int i=1;i<4;i++ ) cin >> c >> x[i] >> c >> y[i]; bool f=true; for( int i=0;i<4;i++ ){ int j = (i+1)%4, k=(i+2)%4, l=(i+3)%4; double ax=x[i]-x[j], ay=y[i]-y[j]; if( check(ax,ay,x[j]-x[k],y[j]-y[k]) * check(ax,ay,x[j]-x[l],y[j]-y[l]) > 0 ){ }else{ f=false; break; } } if( f ) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <iostream> struct vector2 { double x, y; }; bool is_inner_triangle(const vector2 &p, const vector2 &t1, const vector2 &t2, const vector2 &t3) { vector2 p1 = { t1.x - p.x, t1.y - p.y }, p2 = { t2.x - p.x, t2.y - p.y }, p3 = { t3.x - p.x, t3.y - p.y }; return (p1.x * p2.y - p1.y * p2.x < 0 && p2.x * p3.y - p2.y * p3.x < 0 && p3.x * p1.y - p3.y * p1.x < 0) || (p1.x * p2.y - p1.y * p2.x > 0 && p2.x * p3.y - p2.y * p3.x > 0 && p3.x * p1.y - p3.y * p1.x > 0); } int main() { while (true) { vector2 p[4]; char comma; std::cin >> p[0].x >> comma >> p[0].y; for (int i = 1; i < 4; ++i) std::cin >> comma >> p[i].x >> comma >> p[i].y; if (std::cin.eof()) break; if (is_inner_triangle(p[0], p[1], p[2], p[3]) || is_inner_triangle(p[1], p[2], p[3], p[0]) || is_inner_triangle(p[2], p[3], p[0], p[1]) || is_inner_triangle(p[3], p[0], p[1], p[2])) std::cout << "NO" << std::endl; else std::cout << "YES" << std::endl; } }
#include <iostream> #include <cmath> #include <vector> #include <algorithm> using namespace std; typedef pair<double, double> P; double Helon(P pa, P pb, P pc) { double a, b, c; a = sqrt((pb.first - pa.first) * (pb.first - pa.first) + (pb.second - pa.second) * (pb.second - pa.second)); b = sqrt((pc.first - pb.first) * (pc.first - pb.first) + (pc.second - pb.second) * (pc.second - pb.second)); c = sqrt((pa.first - pc.first) * (pa.first - pc.first) + (pa.second - pc.second) * (pa.second - pc.second)); double s = (a + b + c) / 2; return(sqrt(s * (s - a) * (s - b) * (s - c))); } void solve() { vector<P> p(4); while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &p[0].first, &p[0].second, &p[1].first, &p[1].second, &p[2].first, &p[2].second, &p[3].first, &p[3].second)) { double S1, S2; S1 = Helon(p[0], p[1], p[2]); S1 += Helon(p[0], p[2], p[3]); S2 = Helon(p[0], p[1], p[3]); S2 += Helon(p[1], p[2], p[3]); if(fabs(S1 - S2) < 1e-10) { cout << "YES" << endl; } else { cout << "NO" << endl; } } } int main() { solve(); return(0); }
#include<iostream> #include<cmath> using namespace std; //凹んでたら小さい方の角をとってしまう //内角の和が360度か double check(double x1, double y1, double x2, double y2, double x3, double y3) { double e1 = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)); double e2 = sqrt(pow(x3 - x2, 2) + pow(y3 - y2, 2)); double e3 = sqrt(pow(x3 - x1, 2) + pow(y3 - y1, 2)); double Cos = (e1 * e1 + e2 * e2 - e3 * e3) / (2 * e1 * e2); double PI = (double)acos(-1); return acos(Cos) * 180 / PI; } int main() { double xa, ya, xb, yb, xc, yc, xd, yd; char c; while (cin >> xa >> c >> ya >> c >> xb >> c >> yb >> c >> xc >> c >> yc >> c >> xd >> c >> yd) { double r1, r2, r3, r4; r1 = check(xa, ya, xb, yb, xc, yc); r2 = check(xb, yb, xc, yc, xd, yd); r3 = check(xc, yc, xd, yd, xa, ya); r4 = check(xd, yd, xa, ya, xb, yb); //cout << r1 << " " << r2 << " " << r3 << " " << r4 << endl; double sum = r1 + r2 + r3 + r4; //cout << sum << endl; if (sum >= 359 && sum <= 361) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; double check(double x1,double y1,double x2,double y2,double x3,double y3); int main(void){ double xa,xb,xc,xd,ya,yb,yc,yd; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF){ double sq1S=check(xa,ya,xb,yb,xc,yc)+check(xa,ya,xd,yd,xc,yc); double sq2S=check(xb,yb,xc,yc,xd,yd)+check(xb,yb,xa,ya,xd,yd); double var=sq1S-sq2S; if(fabs(var)<=0.01)cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; } double check(double x1,double y1,double x2,double y2,double x3,double y3){ double ab,bc,ca; double S,s; ab=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); bc=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)); ca=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1)); s=0.5*(ab+bc+ca); S=sqrt(s*(s-ab)*(s-bc)*(s-ca)); return S; }
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<cstdio> #include<cstring> #include<complex> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define REP(n) rep(i,n) #define all(n) n.begin(),n.end() // vector(geometric) definition typedef complex<double> cdouble; // define with polor const int N = 4; int main() { cdouble v[N + 2]; double x[N], y[N]; char t; while(cin>>x[0]>>t>>y[0]>>t >>x[1]>>t>>y[1]>>t >>x[2]>>t>>y[2]>>t >>x[3]>>t>>y[3]) { REP(N) v[i] = cdouble(x[i], y[i]); v[N] = v[0]; v[N + 1] = v[1]; double ang[N + 2]; //REP(6)cout << v[i] << endl; for(int i = 1; i <= 4; i++) { ang[i] = fmod( arg(v[i - 1] - v[i]) - arg(v[i + 1] - v[i]) + (10 * M_PI), M_PI * 2); //cout << i << "th angle = " << ang[i] << endl; } int ans = 1; if(ang[1] > M_PI) {REP(4)if(ang[i + 1] < M_PI) ans = 0; } else {REP(4)if(ang[i + 1] > M_PI) ans = 0;} if(ans) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> using namespace std; struct point { double x, y; }p[5]; double dis(point A, point B) { return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y)); } double crossProd(point A, point B, point C) { return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x); } int cmp(const void *a, const void *b) { point *c = (point *)a; point *d = (point *)b; double k = crossProd(p[0], *c, *d); if (k < 0 || !k && dis(p[0], *c) > dis(p[0], *d)) return 1; return -1; } bool solve() { double x = p[0].x; double y = p[0].y; int mi = 0; for (int i=1; i<4; ++i) { if (p[i].y < y || p[i].y == y && p[i].x < x) { x = p[i].x; y = p[i].y; mi = i; } } point tmp = p[0]; p[0] = p[mi]; p[mi] = tmp; qsort(p, 4, sizeof(point), cmp); if (crossProd(p[0], p[1], p[2]) > 0 && crossProd(p[1], p[2], p[3]) > 0 && crossProd(p[2], p[3], p[0]) > 0) return true; return false; } int main() { while (scanf("%lf,%lf", &p[0].x, &p[0].y) != EOF) { for (int i=1; i<4; ++i) scanf (",%lf,%lf", &p[i].x, &p[i].y); bool yes = solve(); if (yes) printf ("YES\n"); else printf ("NO\n"); } return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { const double PI = acos(-1); double x[4], y[4]; char c; while (cin >> x[0] >> c >> y[0] >> c >> x[1] >> c >> y[1] >> c >> x[2] >> c >> y[2] >> c >> x[3] >> c >> y[3]) { bool f = 1; int s = 0; double t = atan2(y[2] - y[1], x[2] - x[1]) - atan2(y[1] - y[0], x[1] - x[0]); if (t > 0) s = 1; for (int i = 1; i < 4; i++) { int j = (i + 1) % 4, k = (i + 2) % 4; t = atan2(y[k] - y[j], x[k] - x[j]) - atan2(y[j] - y[i], x[j] - x[i]); if (t < -PI) t += PI * 2; else if (t > PI) t -= PI * 2; if (!((s == 1 && t > 0) || (s == 0 && t < 0))) { f = 0; break; } } if (f) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <iostream> using namespace std; double crs(double x1, double y1, double x2, double y2) { return x1 * y2 - y1 * x2; } int main() { double x[4], y[4]; char c; while (cin>>x[0]>>c>>y[0]>>c>>x[1]>>c>>y[1]>>c>>x[2]>>c>>y[2]>>c>>x[3]>>c>>y[3]) { int sum = 0; for (int i=0; i<4; ++i) { sum += 0 < crs(x[(i+1)%4] - x[i], y[(i+1)%4] - y[i], x[(i+2)%4] - x[(i+1)%4], y[(i+2)%4] - y[(i+1)%4]); } cout << (sum % 4 == 0 ? "YES" : "NO") << endl; } return 0; }
#include <iostream> #include <cstdio> #include <complex> #include <vector> #include <algorithm> #include <cmath> using namespace std; const double EPS = 1e-10; const double INF = 1e12; #define EQ(n,m) (abs((n)-(m)) < EPS) #define X real() #define Y imag() typedef complex<double> P; typedef vector<P> VP; double dot(P a, P b){ return (conj(a)*b).X; } double cross(P a, P b){ return (conj(a)*b).Y; } int ccw(P a, P b, P c){ b -= a; c -= a; if(cross(b,c) > EPS) return +1; //ccw if(cross(b,c) <-EPS) return -1; //cw if(dot(b,c) < EPS) return +2; //c-a-b if(norm(b) < norm(c)) return -2; //a-b-c return 0; //a-c-b } int main(){ double x[4], y[4]; while(scanf("%lf,%lf", &x[0], &y[0])!=EOF){ for(int i=1; i<4; i++){ scanf(",%lf,%lf", &x[i], &y[i]); } VP quad(4); for(int i=0; i<4; i++){ quad[i] = P(x[i], y[i]); } int judge=1; for(int i=0; i<4; i++){ judge *= ccw(quad[i], quad[(i+1)%4], quad[(i+2)%4]); } if(judge==1){ cout << "YES" << endl; }else{ cout << "NO" << endl; } } return 0; }
#include <iostream> using namespace std; class Point{ public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator +(Point p) { return Point(x+p.x, y+p.y); } Point operator -(Point p) { return Point(x-p.x, y-p.y); } Point operator *(double a) { return Point(x*a, y*a); } }; typedef Point Vector; double cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; } int main() { Point p[4]; while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &p[0].x, &p[0].y, &p[1].x, &p[1].y, &p[2].x, &p[2].y, &p[3].x, &p[3].y) != EOF) { bool okFlag = true; for(int i = 0; i < 4; i++) { int idx1, idx2, idx3; idx1 = (i+1)%4; idx2 = (i+2)%4; idx3 = (i+3)%4; if(cross(p[idx1]-p[i], p[idx2]-p[i]) *cross(p[idx2]-p[i], p[idx3]-p[i]) < 0) { okFlag = false; break; } } if(okFlag) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
#include <complex> #include <iostream> using namespace std; typedef complex<double> P; double cr(P a, P b) { return (conj(a) * b).imag(); } int main() { P a, b, c, d; double x1, y1, x2, y2, x3, y3, x4, y4; char cm; while (cin >> x1 >> cm >> y1 >> cm >> x2 >> cm >> y2 >> cm >> x3 >> cm >> y3 >> cm >> x4 >> cm >> y4) { a = P(x1, y1), b = P(x2, y2), c = P(x3, y3), d = P(x4, y4); P e = a - b, f = b - c, g = c - d, h = d - a; double i = cr(e, f), j = cr(f, g), k = cr(g, h), l = cr(h, e); cout << ((i > 0 && j > 0 && k > 0 && l > 0) || (i < 0 && j < 0 && k < 0 && l < 0) ? "YES" : "NO") << endl; } }
#include<bits/stdc++.h> #include<vector> #include<list> #include<stack> #include<queue> #include<algorithm> #include<map> #include<cmath> #include<complex> using namespace std; typedef complex<double> P; #define X real() #define Y imag() double is_X (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(){ int mod=1000000007; int a,b,c; double xa,xb,xc,xd,ya,yb,yc,yd; while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF) { P a(xa,ya); P b(xb,yb); P c(xc,yc); P d(xd,yd); if (is_X(a,c,b,d)>0.0 || is_X(b,d,a,c)>0.0) { printf("NO\n"); } else { printf("YES\n"); } } return 0; }
#include <complex> #include <cstdio> #include <cmath> using namespace std; // ?????§?¨?????????¨?????? typedef complex<double> P; //XY??§?¨? #define X real() #define Y imag() // ??´???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(){ double xa, xb, xc, xd, ya, yb, yc, yd; while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF ){ P a( xa , ya ); P b( xb , yb ); P c( xc , yc ); P d( xd , yd ); if( isIntersect(a,c,b,d) > 0.0 || isIntersect(b,d,a,c) > 0.0 ){ printf("NO\n"); }else{ printf("YES\n"); } } }
#include <iostream> #include <cstdio> using namespace std; double isConvex(double xa, double ya, double xb, double yb, double x, double y) { double ret; ret = (xa-xb)*(y-ya) + (ya-yb)*(xa-x); return ret; } int main() { double xa, ya, xb, yb, xc, yc, xd, yd; while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF ){ // 直線BDと線分ACが交わるか double bd_ac = isConvex(xb, yb, xd, yd, xa, ya)*isConvex(xb, yb, xd, yd, xc, yc); // 直線ACと線分BDが交わるか double ac_bd = isConvex(xa, ya, xc, yc, xb, yb)*isConvex(xa, ya, xc, yc, xd, yd); // bd_acが負またはac_bdが負ならば、交差している if( bd_ac < 0.0 && ac_bd < 0.0 ){ cout<<"YES"<<endl; }else{ cout<<"NO"<<endl; } } return 0; }