Advertisement
Nickpips

YAY FOR MATH

Feb 28th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <fstream>
  5. #include <math.h>
  6. #include <vector>
  7. #include <bitset>
  8. #include <string>
  9. #include <stack>
  10. #include <queue>
  11. #include <map>
  12. #include <set>
  13. #define _CRT_SECURE_NO_DEPRECATE
  14.  
  15. using namespace std;
  16.  
  17. string filename( "palsquare" );
  18. ifstream in( filename+".in" );
  19. ofstream out( filename+".out" );
  20.  
  21. double crossproduct( double x1, double y1, double x2, double y2 )
  22. {
  23.     return x1*y2 - y1*x2;
  24. }
  25.  
  26. bool capturedpt( double x1, double y1, double minx, double maxx, double miny, double maxy )
  27. {
  28.     if( minx < x1 && maxx >= x1 &&
  29.         miny < y1 && maxy >= y1 )
  30.         return true;
  31.     else
  32.         return false;
  33. }
  34.  
  35. double MAX( double a, double b, double c, double d )
  36. {
  37.     return max( a, max( b, max( c, d ) ) );
  38. }
  39.  
  40. int main()
  41. {
  42.     double x1 = 2;
  43.     double y1 = 6;
  44.     double x2 = 5;
  45.     double y2 = 5;
  46.     double x3 = 6;
  47.     double y3 = 2;
  48.     double x4 = 4;
  49.     double y4 = 10;
  50.  
  51.     double MAXY = MAX( y1, y2, y3, y4 ) + 1;
  52.     double MAXX = MAX( x1, x2, x3, x4 )+1;
  53.     double SCALE = 20.0;
  54.  
  55.     for( double y = 0; y <= MAXY; y += MAXY/SCALE )
  56.     {
  57.         for( double x = 0; x <= MAXX; x += MAXX/SCALE )
  58.         {
  59.             if( capturedpt( x1, y1, x, x+ MAXX/SCALE, y, y+ MAXY/SCALE ) )
  60.                 cout << "A";
  61.             else if( capturedpt( x2, y2, x, x+ MAXX/SCALE, y, y+ MAXY/SCALE ) )
  62.                 cout << "a";
  63.             else if( capturedpt( x3, y3, x, x+ MAXX/SCALE, y, y+ MAXY/SCALE ) )
  64.                 cout << "B";
  65.             else if( capturedpt( x4, y4, x, x+ MAXX/SCALE, y, y+ MAXY/SCALE ) )
  66.                 cout << "b";
  67.             else
  68.                 cout << ".";
  69.         }
  70.         cout << endl;
  71.     }
  72.     if( crossproduct( x3-x1, y3-y1, x3-x2, y3-y2 ) * crossproduct( x4-x1, y4-y1, x4-x2, y4-y2 ) < 0
  73.         && crossproduct( x1-x3, y1-y3, x1-x4, y1-y4 ) * crossproduct( x2-x3, y2-y3, x2-x4, y2-y4 ) < 0 )
  74.         cout << "THEY INTERSECT!";
  75.     else
  76.         cout << "THEY DON'T INTERSECT!";
  77.     cin.get();
  78.  
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement