Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <vector>
- #include <map>
- #include <set>
- #include <time.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <algorithm>
- #include <math.h>
- using namespace std;
- ifstream fin("circles.in");
- ofstream fout("circles.out");
- //ifstream fin("input.txt");
- //ofstream fout("output.txt");
- //#define fin cin
- //#define fout cout
- #define all(x) x.begin(), x.end()
- struct Point {
- public:
- double x, y;
- int id;
- Point() {};
- Point(double x, double y, int id): x(x), y(y), id(id) {};
- };
- struct Vector {
- public:
- double x, y;
- Vector() {};
- Vector(Point A, Point B) {
- x = B.x - A.x;
- y = B.y - A.y;
- };
- };
- double Kosoe(Vector a, Vector b) {
- return a.x * b.y - a.y * b.x;
- }
- Point peres(Point P1, Point P2, Point P3) { //точка пересечения серединных перпендикуляров (центр описанной окружности)
- double a1, a2, b1, b2, c1, c2;
- a1 = P2.x - P1.x;
- b1 = P2.y - P1.y;
- c1 = -(P2.x - P1.x) * (P1.x + P2.x) / 2 - (P2.y - P1.y) * (P1.y + P2.y) / 2;
- c1 = -c1;
- a2 = P3.x - P1.x;
- b2 = P3.y - P1.y;
- c2 = -(P3.x - P1.x) * (P1.x + P3.x) / 2 - (P3.y - P1.y) * (P1.y + P3.y) / 2;
- c2 = -c2;
- double X = (b2 * c1 - b1 * c2) / (a1 * b2 - a2 * b1);
- double Y = (a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1);
- return Point(X, Y, 0);
- }
- double dist (Point A, Point B) {
- return sqrt( (A.x-B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y) );
- }
- bool Equal (double x, double y) {
- return fabs(x-y) < 1e-7;
- }
- bool Less(double x, double y) {
- return !Equal(x,y) && x < y;
- }
- int main() {
- int n;
- fin >> n;
- vector<Point> P(n);
- for (int i=0; i<n; i++) {
- fin >> P[i].x >> P[i].y;
- P[i].id = i + 1;
- }
- if (n == 2) {
- fout << "1" << endl << "2" << endl;
- return 0;
- } else
- if (n == 3) {
- fout << "1 2" << endl;
- fout << "3" << endl;
- return 0;
- }
- else
- if (n == 4) {
- fout << "1 2" << endl;
- fout << "3 4" << endl;
- return 0;
- }
- vector<int> ans1, ans2;
- for (int i=1; i<n; i++)
- for (int j=i+1; j<n; j++) {
- ans1.clear();
- ans2.clear();
- Point O = peres(P[0], P[i], P[j]);
- vector<bool> used(n+1, false);
- double R = dist(O, P[0]);
- for (int k=0; k<n; k++)
- if (Equal(R, dist(P[k], O))) {
- used[k] = true;
- ans1.push_back(P[k].id);
- }
- int first = -1;
- for (int k=0; k<n; k++)
- if (!used[k]) {
- if (first == -1) first = k;
- break;
- }
- if (first == -1) {
- for (int i=0; i<(int) ans1.size(); i++)
- fout << ans1[i] << ' ';
- fout << endl << "1";
- return 0;
- }
- for (int k=first+1; k<n; k++)
- for (int l=k+1; l<n; l++) {
- Point O2 = peres(P[first], P[k], P[l]);
- double R2 = dist(O2, P[first]);
- for (int z=0; z<n; z++)
- if (Equal(R2, dist(P[z], O2))) {
- used[z] = true;
- ans2.push_back(P[z].id);
- }
- bool DONE = true;
- for (int z=0; z<n; z++)
- if (!used[z]) {
- DONE = false;
- break;
- }
- if (DONE) {
- sort(all(ans1));
- sort(all(ans2));
- ans1.erase(unique(all(ans1)), ans1.end());
- ans2.erase(unique(all(ans2)), ans2.end());
- for (int i=0; i< ans1.size(); i++) fout << ans1[i] << ' ';
- fout << endl;
- for (int i=0; i< ans2.size(); i++) fout << ans2[i] << ' ';
- return 0;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement