Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <fstream>
- #include <math.h>
- #include <vector>
- #include <bitset>
- #include <string>
- #include <stack>
- #include <queue>
- #include <map>
- #include <set>
- #define _CRT_SECURE_NO_DEPRECATE
- using namespace std;
- string filename( "palsquare" );
- ifstream in( filename+".in" );
- ofstream out( filename+".out" );
- double crossproduct( double x1, double y1, double x2, double y2 )
- {
- return x1*y2 - y1*x2;
- }
- bool capturedpt( double x1, double y1, double minx, double maxx, double miny, double maxy )
- {
- if( minx < x1 && maxx >= x1 &&
- miny < y1 && maxy >= y1 )
- return true;
- else
- return false;
- }
- double MAX( double a, double b, double c, double d )
- {
- return max( a, max( b, max( c, d ) ) );
- }
- int main()
- {
- double x1 = 2;
- double y1 = 6;
- double x2 = 5;
- double y2 = 5;
- double x3 = 6;
- double y3 = 2;
- double x4 = 4;
- double y4 = 10;
- double MAXY = MAX( y1, y2, y3, y4 ) + 1;
- double MAXX = MAX( x1, x2, x3, x4 )+1;
- double SCALE = 20.0;
- for( double y = 0; y <= MAXY; y += MAXY/SCALE )
- {
- for( double x = 0; x <= MAXX; x += MAXX/SCALE )
- {
- if( capturedpt( x1, y1, x, x+ MAXX/SCALE, y, y+ MAXY/SCALE ) )
- cout << "A";
- else if( capturedpt( x2, y2, x, x+ MAXX/SCALE, y, y+ MAXY/SCALE ) )
- cout << "a";
- else if( capturedpt( x3, y3, x, x+ MAXX/SCALE, y, y+ MAXY/SCALE ) )
- cout << "B";
- else if( capturedpt( x4, y4, x, x+ MAXX/SCALE, y, y+ MAXY/SCALE ) )
- cout << "b";
- else
- cout << ".";
- }
- cout << endl;
- }
- if( crossproduct( x3-x1, y3-y1, x3-x2, y3-y2 ) * crossproduct( x4-x1, y4-y1, x4-x2, y4-y2 ) < 0
- && crossproduct( x1-x3, y1-y3, x1-x4, y1-y4 ) * crossproduct( x2-x3, y2-y3, x2-x4, y2-y4 ) < 0 )
- cout << "THEY INTERSECT!";
- else
- cout << "THEY DON'T INTERSECT!";
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement