예제 #1
0
파일: DOORSPEN.cpp 프로젝트: Harshit44/spoj
void andrewScan(vp &polys,P *ps,int n) {
  u.clear(); l.clear();
  polys.clear();
  if(n < 3) return ;

  sort(ps,ps+n,cmpx);
  
  u.pb(ps[0]);
  u.pb(ps[1]);
  l.pb(ps[n-1]);
  l.pb(ps[n-2]);

  for(int i = 2;i < n;i++) {
    for(int j = u.size();j >= 2 && ccw(u[j-2],u[j-1],ps[i]) != 2;j--)
      u.pop_back();
    u.pb(ps[i]);
  }

  for(int i = n-3;i >= 0;i--) {
    for(int j = l.size();j >= 2 && ccw(l[j-2],l[j-1],ps[i]) != 2;j--)
      l.pop_back();
    l.pb(ps[i]);
  }

  polys = l;
  for(int i = 1;i < u.size()-1;i++) polys.pb(u[i]);
}
예제 #2
0
int main() {
  int n, cases=0;
  while(1) {
    cin >> n;

    // End of cases
    if(n == 0) break;

    // Init
    points.clear();
    int x, y;

    // Read in points
    for (int i = 0; i < n; ++i) {
      cin >> x >> y;
      points.push_back(point(x,y));
    }

    double convex_hull_area = area(CH(points));

    // Complete the polygon, if necessary
    if(!(points.back() == points.front()))
      points.push_back(points.front());

    double total_area = area(points);

    double percent_diff = (convex_hull_area - total_area) / convex_hull_area * 100;

    cout << "Tile #" << ++cases << endl;
    cout << "Wasted Space = " << setprecision(2) << fixed << percent_diff << " " << '%' << endl << endl;

  }

  return 0;
}
예제 #3
0
int main(){
	int N, n_ind, t, combs, n_morto;
	point input;
	double p_killed;

	cin >> t;
	while(t--){
		cin >> n_ind;

		N = n_ind;
		combs = (N*(N-1)*(N-2))/6;

		positions.clear();

		while(n_ind--){
			cin >> input.x >> input.y;

			positions.push_back(input);
		}

		n_morto = 0;

		for(vp::iterator ii = positions.begin(); ii != positions.end(); ++ii){
			for(vp::iterator jj = ii+1; jj != positions.end(); ++jj){
				for(vp::iterator kk = jj+1; kk != positions.end(); ++kk){
					n_morto += calc_morto(ii,jj,kk);
				}
			}
		}

		p_killed = ((double)n_morto)/(combs * ((positions.size()-3)));
		cout << setprecision(8) << p_killed << "\n";

	}
}