Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #include <math.h>
- #define pii pair <int,int>
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- struct ipn{
- int x,y;
- };
- struct rpn{
- db x,y;
- };
- rpn rVec(rpn A, rpn B){
- rpn ab;
- ab.x = A.x - B.x;
- ab.y = A.y - B.y;
- return ab;
- }
- rpn div(rpn A, rpn B, db p, db q){
- rpn res;
- res.x = (q * A.x + p * B.x) / (p + q);
- res.y = (q * A.y + p * B.y) / (p+q);
- return res;
- }
- db dot(rpn a, rpn b){
- return a.x * b.x + a.y * b.y;
- }
- db lgth(rpn a){
- return sqrt(a.x * a.x + a.y * a.y);
- }
- db angl(rpn a, rpn b){
- db an = acos(dot(a, b) / ( lgth(a) * lgth(b)) );
- return an;
- }
- db rCross(rpn a, rpn b){
- return a.y * b.x - a.x * b.y;
- }
- int anglTp(rpn A, rpn B, rpn C){ //возвращает тип угла между AB и AC то есть угла BAC
- rpn ab = rVec(A, B);
- rpn ac = rVec(A, C);
- if (dot(ab, ac) > 0){
- return 1; //острый
- }
- if (dot(ab, ac) == 0){
- return 1;//прямой
- }
- return 2; // тупой
- }
- db rArea(rpn A, rpn B, rpn C){
- rpn ab = rVec(A, B);
- rpn ac = rVec(A, C);
- return fabs( rCross(ab, ac) ); // 2.0
- }
- db hgt(rpn A, rpn B, rpn C){ //height
- db h;
- //cout<<"rArea(B, A, C) = "<<rArea(B, A, C) <<"\n";
- //cout<<"AB = "<<lgth(rVec(A, B))<<"\n";
- h = rArea(B, A, C) / lgth( rVec(A, B) );
- //cout<<"h = "<<h<<"\n";
- if ( anglTp(A, B, C) == 2){
- //cout<<"one\n";
- return lgth( rVec(C, A) );
- }
- if (anglTp (B, A, C) == 2){
- //cout<<"two\n";
- return lgth( rVec(C, B) );
- }
- return h;
- }
- void mk(rpn &x){
- cin>>x.x>>x.y;
- }
- db eps = 1e-7;
- int sgn(db x){
- if (x > 0.0) return 1;
- else if (x == 0.0) return 0;
- return -1;
- }
- bool eq(rpn A, rpn B){
- return A.x == B.x && A.y == B.y;
- }
- bool inter(rpn A, rpn B, rpn C, rpn D){
- if (eq(A,C) || eq(A,D ) || eq(B, C) || eq(B,D)){
- return 1;
- }
- if (A.x > B.x) swap(A, B);
- if (C.x > D.x) swap(C, D);
- if (B.x < C.x) {
- //cout<<"one\n";
- return 0;
- }
- if (D.x < A.x) {
- //cout<<"two\n";
- return 0;
- }
- if (A.y > B.y) swap(A, B);
- if (C.y > D.y) swap(C, D);
- if (B.y < C.y) return 0;
- if (D.y < A.y ) return 0;
- if ( sgn(rCross(rVec(A,B), rVec(C,D)) == 0.0) ){
- return 1;
- }
- if (sgn(rCross(rVec(A,B), rVec(A,C))) == sgn(rCross(rVec(A,B), rVec(A,D)))){
- /*cout<<"three\n";
- //сout<<"sgn(rCross(rVec(A,B), rVec(A,C))) = "<<sgn(rCross(rVec(A,B), rVec(A,C)))<<"\n";
- cout<<"sgn(rCross(rVec(A,B), rVec(A,C))) = "<<sgn(rCross(rVec(A,B), rVec(A,C)))<<"\n";
- cout<<"sgn(rCross(rVec(A,B), rVec(A,D))) = "<<sgn(rCross(rVec(A,B), rVec(A,D)))<<"\n";*/
- return 0;
- }
- if (sgn(rCross(rVec(C,D), rVec(C, A))) == sgn(rCross(rVec(C, D), rVec(C,B)))){
- /*cout<<"four\n";
- cout<<"sgn(rCross(rVec(C,D), rVec(C, A))) = "<<sgn(rCross(rVec(C,D), rVec(C, A)))<<"\n";
- cout<<"sgn(rCross(rVec(C, D), rVec(C,B))) = "<<sgn(rCross(rVec(C, D), rVec(C,B)))<<"\n";*/
- return 0;
- }
- return 1;
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout.precision(20);
- rpn A,B,C,D;
- mk(A);
- mk(B);
- mk(C);
- mk(D);
- if (inter(A,B, C,D)){
- cout<<"YES\n";
- }
- else cout<<"NO\n";
- }
- /*
- 0 0 10 10
- 0 4 10 4
- 0 0 10 0
- 9 0 100 0
- 1 1 1 6
- 1 4 3 5
- 1 1 1 6
- 3 1 3 6
- 3 3 12 12
- 6 6 9 9
- 3 3 5 6
- 3 5 7 5
- 1 2 1 2
- 1 2 1 2
- 3 3 5 6
- 5 6 3 3
- 3 3 5 6
- 1 2 4 2
- 5 4 8 4
- 3 3 5 6
- */
Add Comment
Please, Sign In to add comment