Advertisement
Guest User

7_task

a guest
Jan 21st, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.37 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <vector>
  4. #include <map>
  5. #include <set>
  6. #include <time.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <algorithm>
  10. #include <math.h>
  11.  
  12. using namespace std;
  13.  
  14. ifstream fin("circles.in");
  15. ofstream fout("circles.out");
  16.  
  17. //ifstream fin("input.txt");
  18. //ofstream fout("output.txt");
  19.  
  20. //#define fin cin
  21. //#define fout cout
  22.  
  23. #define all(x) x.begin(), x.end()
  24.  
  25. struct Point {
  26. public:
  27.     double x, y;
  28.     int id;
  29.     Point() {};
  30.     Point(double x, double y, int id): x(x), y(y), id(id) {};
  31. };
  32.  
  33. struct Vector {
  34. public:
  35.     double x, y;
  36.     Vector() {};
  37.     Vector(Point A, Point B) {
  38.         x = B.x - A.x;
  39.         y = B.y - A.y; 
  40.     };
  41. };
  42.  
  43. double Kosoe(Vector a, Vector b) {
  44.     return a.x * b.y - a.y * b.x;
  45. }
  46.  
  47. Point peres(Point P1, Point P2, Point P3) { //точка пересечения серединных перпендикуляров (центр описанной окружности)
  48.     double a1, a2, b1, b2, c1, c2;
  49.     a1 = P2.x - P1.x;
  50.     b1 = P2.y - P1.y;
  51.     c1 = -(P2.x - P1.x) * (P1.x + P2.x) / 2 - (P2.y - P1.y) * (P1.y + P2.y) / 2;
  52.     c1 = -c1;
  53.  
  54.     a2 = P3.x - P1.x;
  55.     b2 = P3.y - P1.y;
  56.     c2 = -(P3.x - P1.x) * (P1.x + P3.x) / 2 - (P3.y - P1.y) * (P1.y + P3.y) / 2;
  57.     c2 = -c2;
  58.  
  59.     double X = (b2 * c1 - b1 * c2) / (a1 * b2 - a2 * b1);
  60.     double Y = (a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1);
  61.     return Point(X, Y, 0);
  62. }
  63.  
  64. double dist (Point A, Point B) {
  65.     return sqrt( (A.x-B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y) );
  66. }
  67.  
  68. bool Equal (double x, double y) {
  69.     return fabs(x-y) < 1e-7;
  70. }
  71.  
  72. bool Less(double x, double y) {
  73.     return !Equal(x,y) && x < y;
  74. }
  75.  
  76. int main() {
  77.  
  78.     int n;
  79.     fin >> n;
  80.     vector<Point> P(n);
  81.     for (int i=0; i<n; i++) {
  82.         fin >> P[i].x >> P[i].y;
  83.         P[i].id = i + 1;
  84.     }
  85.  
  86.     if (n == 2) {
  87.         fout << "1" << endl << "2" << endl;
  88.         return 0;
  89.     } else
  90.     if (n == 3) {
  91.         fout << "1 2" << endl;
  92.         fout << "3" << endl;
  93.         return 0;
  94.     }
  95.     else
  96.     if (n == 4) {
  97.         fout << "1 2" << endl;
  98.         fout << "3 4" << endl;
  99.         return 0;
  100.      }
  101.  
  102.     vector<int> ans1, ans2;
  103.    
  104.     for (int i=1; i<n; i++)
  105.         for (int j=i+1; j<n; j++) {
  106.             ans1.clear();
  107.             ans2.clear();
  108.             Point O = peres(P[0], P[i], P[j]);
  109.             vector<bool> used(n+1, false);
  110.             double R = dist(O, P[0]);
  111.             for (int k=0; k<n; k++)
  112.                 if (Equal(R, dist(P[k], O))) {
  113.                     used[k] = true;
  114.                     ans1.push_back(P[k].id);
  115.                 }
  116.             int first = -1;
  117.             for (int k=0; k<n; k++)
  118.                 if (!used[k]) {
  119.                     if (first == -1) first = k;
  120.                     break;
  121.                 }
  122.             if (first == -1) {
  123.                 for (int i=0; i<(int) ans1.size(); i++)
  124.                     fout << ans1[i] << ' ';
  125.                 fout << endl << "1";
  126.                 return 0;
  127.             }
  128.            
  129.             for (int k=first+1; k<n; k++)
  130.                 for (int l=k+1; l<n; l++) {
  131.                     Point O2 = peres(P[first], P[k], P[l]);
  132.                     double R2 = dist(O2, P[first]);
  133.                     for (int z=0; z<n; z++)
  134.                         if (Equal(R2, dist(P[z], O2))) {
  135.                             used[z] = true;
  136.                             ans2.push_back(P[z].id);
  137.                         }
  138.                    
  139.                     bool DONE = true;
  140.                     for (int z=0; z<n; z++)
  141.                         if (!used[z]) {
  142.                             DONE = false;
  143.                             break;
  144.                         }
  145.  
  146.                 if (DONE) {
  147.                     sort(all(ans1));
  148.                     sort(all(ans2));
  149.                     ans1.erase(unique(all(ans1)), ans1.end());
  150.                     ans2.erase(unique(all(ans2)), ans2.end());
  151.  
  152.                     for (int i=0; i< ans1.size(); i++) fout << ans1[i] << ' ';
  153.                     fout << endl;
  154.                     for (int i=0; i< ans2.size(); i++) fout << ans2[i] << ' ';                     
  155.                     return 0;
  156.                     }
  157.                 }
  158.         }
  159.  
  160.  
  161.  
  162.     return 0;
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement