Example #1
0
int main()
{
    cout<<fixed<<setprecision(0);
    while(true)
    {
        int n;
        cin>>n;
        if (n==0) break;

        vector<Point> points;
        for (int i=0; i<n; i++)
        {
            long x,y;
            cin>>x>>y;
            points.push_back(Point(x,y));
        }

        Triangulation DT;
        DT.insert(points.begin(),points.end());

        int m;
        cin>>m;
        vector<Point> newp;
        //double  min = -1;
        for (int i=0; i<m; i++)
        {
            long x,y;
            cin>>x>>y;
            Point np(x,y);
            newp.push_back(np);
        }

        vector<double> sol;
        for (int i=0; i<m; i++)
        {
            Point np = newp[i];
            Point p = DT.nearest_vertex(np)->point();

            double dist = CGAL::to_double(squared_distance(np,p));
            sol.push_back(dist);

        }

        for (int i=0; i<m; i++) cout<<sol[i]<<endl;



    }
    return 0;
}
Example #2
0
int main() {
  // some basic setup stuff
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cout << fixed << setprecision(0);

  while(true) {
      int existing_count;
      cin >> existing_count;

      // kill switch for application
      if(existing_count == 0) {
        break;
      }

      // collect existing restaurants
      vector<K::Point_2> existing_locs;
      existing_locs.reserve(existing_count);

      for(int i=0; i < existing_count; i++) {
        double loc_x, loc_y;
        cin >> loc_x >> loc_y;

        existing_locs.push_back(K::Point_2(loc_x, loc_y));
      }

      // cosntruct triangulation
      Triangulation triang;
      triang.insert(existing_locs.begin(), existing_locs.end());

      // go through possible location
      int possible_count;
      cin >> possible_count;

      for(int i = 0; i < possible_count; i++) {
        int possible_x, possible_y;
        cin >> possible_x >> possible_y;
        
        K::Point_2 possible_point = K::Point_2(possible_x, possible_y);

        // find nearest vertex and by that the nearest point
        K::Point_2 nearest = triang.nearest_vertex(possible_point)->point();
        cout << CGAL::to_double(CGAL::squared_distance(nearest, possible_point)) << endl;
      }
    }
}
Example #3
0
void testcase(int n) {
	vector<K::Point_2> delaunay_vertices;
	for(int i = 0; i < n; ++i) {
		K::Point_2 p; cin >> p;
		delaunay_vertices.push_back(p);
	}

	Triangulation t;
	t.insert(delaunay_vertices.begin(), delaunay_vertices.end());

	int points; cin >> points;
	for(int i = 0; i < points; ++i) {
		K::Point_2 p; cin >> p;
		Triangulation::Vertex_handle v = t.nearest_vertex(p);
		K::Point_2 vp = v->point();
		K::FT distance = CGAL::squared_distance(p, vp);
		cout << floor_to_double(distance) << "\n";
	}
}
 	void remove_blue_point(Point p){
        	blue_points.erase(std::remove(blue_points.begin(), blue_points.end(), p), blue_points.end());
		blue_red_t.remove(blue_red_t.nearest_vertex(p));
	}