Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <string>
  6. #include <iomanip>
  7. #include <fstream>
  8. #include <map>
  9.  
  10. using namespace std;
  11.  
  12. struct Point
  13. {
  14.     double x;
  15.     double y;
  16. };
  17.  
  18. struct Vector
  19. {
  20.     Point b;
  21.     Point e;
  22. };
  23.  
  24. inline double Cross(Vector p, Point T)
  25. {
  26.     return (p.e.x - p.b.x)*(T.y - p.b.y) - (p.e.y - p.b.y)*(T.x - p.b.x);
  27. }
  28.  
  29. int main()
  30. {
  31.     ofstream fout("output.txt");
  32.     ifstream fin("input.txt");
  33.     int N, M;
  34.  
  35.     fin >> N >> M;
  36.     vector<Point> points(N);
  37.     vector<Vector> vectors(M);
  38.     for(int i = 0; i < N; ++i) fin >> points[i].x >> points[i].y;
  39.     for(int i = 0; i < M; ++i) fin >> vectors[i].b.x >> vectors[i].b.y >> vectors[i].e.x >> vectors[i].e.y;
  40.  
  41.     for(int i = 0; i < M; ++i)
  42.     {
  43.         double A = vectors[i].e.y - vectors[i].b.y;
  44.         double B = -(vectors[i].e.x - vectors[i].b.x);
  45.         double C = vectors[i].b.y*(-B) - vectors[i].b.x*A;
  46.  
  47.         for(int j = 0; j < N; ++j)
  48.         {
  49.             if(Cross(vectors[i], points[j]) <= 0)
  50.             {
  51.                 Point N;
  52.                 double A2 = B;
  53.                 double B2 = -A;
  54.                 double C2 = A*points[j].y - B*points[j].x;
  55.  
  56.                 double My = (-A*C2+A2*C)/(B2*A-B*A2);
  57.                 double Mx = -(C+B*My)/A;
  58.  
  59.                 N.x = 2*Mx - points[j].x;
  60.                 N.y = 2*My - points[j].y;
  61.  
  62.                 points[j] = N;
  63.             }
  64.            
  65.         }
  66.     }
  67.     for(int i = 0; i < N; ++i) fout << fixed << setprecision(10) << points[i].x << " " << points[i].y << endl;
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement