Exemple #1
0
vpll convex_hull (vpll points) {
	i64 xmin = points[0].x_;
	int min = 0;
	for (int i = 1; i < points.size(); ++i) {
		if ((points[i].x_ < xmin) || (xmin == points[i].x_ && points[i].y_ < points[min].y_)) {
			xmin = points[i].x_;
			min = i;
		}
	}
	//cout << "min" << points[min].x_ << ' ' << points[min].y_ << endl;
	swap(points[0], points[min]);
	p0 = points[0];
	sort(points.begin() + 1, points.end(), &cmp);
	for (int i = 0; i < points.size(); ++i) {
		cout << points[i].x_ << " " << points[i].y_ << endl;
	}
	/*
	for (int i = 0; i < points.size(); ++i) {
		cout << points[i].x_ << " " << points[i].y_ << endl;
	}
	*/
	vpll stack;
	stack.pb(points[0]);
	stack.pb(points[1]);
	stack.pb(points[2]);
	for (int i = 3; i < points.size(); ++i) {
		int n = stack.size();
		//cout << "stack_size: " << n << endl;
		while (orientation(stack[n - 2], stack[n - 1], points[i])) {
			//cout << "pop\n";
			stack.pop_back();
			n = stack.size();
		}
		//cout << "push: " << points[i].x_ << ' ' << points[i].y_ << endl;
		stack.pb(points[i]);
	}
	return stack;
}
bool violates(vpll ar, long long k){
	//binary search over inervals
	int lo=0, hi = ar.size()-1; 
	while(lo <=hi){
		int mid = lo + (hi - lo )/2;
		if(ar[mid].first <= k && k <= ar[mid].second )
			return true;
		else if(k < ar[mid].first)
			hi = mid - 1;
		else if(k > ar[mid].second)
			lo = mid + 1;
	}
	return false;
}
Exemple #3
0
inline pll find_max (pll v, vpll &points) {
	int l = 0;
   	int r = points.size() - 1;
   	int m;
   	while (l < r) {
   		m = (l + r)/2;
   		//cout << "m: " << m << endl;
      	if (((points[m + 1].x_ - points[m].x_) * v.x_ > - (points[m + 1].y_ - points[m].y_) * v.y_)) {
      		/*
      		cout << "1: " << (points[m + 1].x_ - points[m].x_) * v.x_ << endl;
      		cout << "2: " << (points[m + 1].y_ - points[m].y_) * v.y_ << endl;
      		cout << " lol " << (points[m + 1].x_ - points[m].x_) * v.x_ + (points[m + 1].y_ - points[m].y_) * v.y_ << endl;
         	*/
         	l = m + 1;    
         //	cout << "l: " << l << endl;
      	} else {
         	r = m;
      	} 
   	}
//   	cout << l << " " << r << endl;
   	return points[l];
}