Example #1
0
long long query_min(int n,int L,int R,int l,int r){
  if (l==L && r==R) return seg_tree_min[n];
  int m = (L + R) >> 1;
  if (r <= m) return query_min(2*n,L,m,l,r);
  if (l > m) return query_min(2*n+1,m+1,R,l,r);
  return min( query_min(2*n,L,m,l,m) , query_min(2*n+1,m+1,R,m+1,r) );
}
Example #2
0
File: Tree.cpp Project: cwchym/ACM
int query_min(int l,int r,int rt,int ll,int rr)
{
	if(l>=ll&&rr>=r)
	{
		return _min[rt];
	}
	
	int mid=(l+r)>>1;
	int tmp1=0x7fffffff,tmp2=0x7fffffff;
	if(ll<=mid) tmp1=query_min(l,mid,rt<<1,ll,rr);
	if(rr>mid) tmp2=query_min(mid+1,r,rt<<1|1,ll,rr);

	return (tmp1<=tmp2)?tmp1:tmp2;
}
Example #3
0
int main(){
  long long res;
  int to,from;
  long long temp1;
  long long temp2;
  while (scanf("%d %d %d %d",&N,&P,&Q,&F) != EOF){
		for (int i=1; i <= N; ++i) scanf("%d",a+i);
		build_tree(1,1,N);
		res = INT_MAX;
		for (int i=1; i < (N-P); ++i){
		  from = i + P + 1;
		  to = min(i+Q+1,N);
		  temp1 = query(1,1,N,from,to);
		  temp2 = INT_MAX;
		  if (to<N){
			 temp2 = query_min(1,1,N,to+1,N);
			 temp2 -= (long long)F*to;
		  }
		  if (temp1 > temp2) temp1 = temp2;
		  if (res > (temp1 + a[i])) res = temp1 + a[i];
		}
		printf("%lld\n",res);
  }
  return 0;
}
Example #4
0
int query_min(int idx,int _l,int _r)
{//类似上面的query_max
	int min,min1;
	if(_l<=node[idx].l && _r >=node[idx].r)
		return node[idx].min;
	if(_r<=node[2*idx].r)
		return query_min(2*idx,_l,_r);
	else
		{
			if(_l>=node[2*idx+1].l)
				{
					return query_min(2*idx+1,_l,_r);
				}
			else
				{
					min=query_min(2*idx,_l,node[2*idx].r);
					min1=query_min(2*idx+1,node[2*idx+1].l,_r);
					if(min<min1)
						return min;
					else
						return min1;
				}
		}
}
Example #5
0
int main(void)
{
	freopen("h.in","r",stdin);
	freopen("h.out","w",stdout);
	int i;
	int max,min;
	int s,e,a;
	int tcase=1;
	init_node(1,1,500000);
	while(EOF != scanf("%d",&n))
		{
			init_p();
			for(i=0;i<500006*4;i++)
				{
					node[i].max=-1;
					node[i].min=500006*4;
				}
			for(i=1;i<=n;i++)
				{
					scanf("%d",&a);
					insert(1,i,i,a);
				}
			scanf("%d",&m);
			for(i=0;i<m;i++)
				{
					scanf("%d%d",&s,&e);
					max=query_max(1,s,e);
					min=query_min(1,s,e);
					union_set(max,min);
				}
			scanf("%d",&k);
			printf("CASE %d\n",tcase);
			tcase++;
			for(i=0;i<k;i++)
				{
					scanf("%d%d",&s,&e);
					ps=find(s);
					pe=find(e);
					if(ps==pe)
						printf("YES\n");
					else
						printf("NO\n");
				}
		}
	return 0;
}
Example #6
0
File: Tree.cpp Project: cwchym/ACM
int main(int argc, char *argv[])
{
	int n,k;
	while(scanf("%d %d",&n,&k)==2)
	{
		build(1,n,1);

		for(int i=1;i<=n-k+1;i++)
			printf("%d ", query_min(1,n,1,i,i+k-1));
		printf("\n");

		for(int i=1;i<=n-k+1;i++)
			printf("%d ", query_max(1,n,1,i,i+k-1));
		printf("\n");
	}
	
	return 0;
}
int main()
{
	int q,m,max1,max2,max3,i,l,r,min;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&stmin[i+n]);
		stmax[n+i]=stmin[n+i];
	}
	build_min_max();
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d%d",&l,&r);
		r++;
		min=query_min(l,r);
		max1=2*query_max(0,l);
		max2=2*query_max(r,n);
		max3=query_max(l,r)-min;
		m=max(max1,max2,max3);
		printf("%0.1lf\n",min+m/2.0);
	}
	return 0;
}
    void
    NormalHoughProposer::houghVote(Entry &query, Entry &target, bin_t& bins)
    {
      // Compute the reference point for the R-table
      Eigen::Vector4f centroid4;
      compute3DCentroid(*(target.cloud), centroid4);
      Eigen::Vector3f centroid(centroid4[0], centroid4[1], centroid4[2]);

      assert(query.keypoints->size() == query.features->size());
      assert(target.keypoints->size() == target.features->size());

      // Figure out bin dimension
      Eigen::Vector4f query_min4, query_max4;
      getMinMax3D(*query.cloud, query_min4, query_max4);
      Eigen::Vector3f query_min(query_min4[0], query_min4[1], query_min4[2]);
      Eigen::Vector3f query_max(query_max4[0], query_max4[1], query_max4[2]);

      Eigen::Affine3f t;
      getTransformation(0, 0, 0, M_PI, 0.5, 1.5, t);

      int correctly_matched = 0;
      for (unsigned int i = 0; i < query.keypoints->size(); i++)
      {
        std::vector<int> feature_indices;
        std::vector<float> sqr_distances;

        int num_correspondences = 2;
        if (!pcl_isfinite (query.features->points.row(i)(0)))
          continue;
        int num_found = target.tree->nearestKSearch(*query.features, i, num_correspondences, feature_indices, sqr_distances);

        for (int j = 0; j < num_found; j++)
        {
          // For each one of the feature correspondences
          int feature_index = feature_indices[j];

          Eigen::Vector3f query_keypoint = query.keypoints->at(i).getVector3fMap();
          Eigen::Vector3f target_keypoint = target.keypoints->at(feature_index).getVector3fMap();

          target_keypoint = t * target_keypoint;
          if ((query_keypoint - target_keypoint).norm() < 0.05)
          {
            correctly_matched++;
          }

          // Get corresponding target keypoint, and calculate its r to its centroid
          PointNormal correspondence = target.keypoints->at(feature_index); // Since features correspond to the keypoints
          Eigen::Vector3f r = correspondence.getVector3fMap() - centroid;

          // Calculate the rotation transformation from the target normal to the query normal
          Eigen::Vector3f target_normal = correspondence.getNormalVector3fMap();
          target_normal.normalize();
          Eigen::Vector3f query_normal = query.keypoints->at(i).getNormalVector3fMap();
          query_normal.normalize();
          double angle = acos( target_normal.dot(query_normal) / (target_normal.norm() * query_normal.norm()) );
          Eigen::Vector3f axis = target_normal.normalized().cross(query_normal.normalized());
          axis.normalize();
          Eigen::Affine3f rot_transform;
          rot_transform = Eigen::AngleAxisf (angle, axis);

          // Check that the rotation matrix is correct
          Eigen::Vector3f projected = rot_transform * target_normal;
          projected.normalize();

          // Transform r based on the difference between the normals
          Eigen::Vector3f transformed_r = rot_transform * r;

          for (int k = 0; k < num_angles_; k++)
          {
            float query_angle = (float(k) / num_angles_) * 2.0f * float (M_PI);
            Eigen::Affine3f query_rot;
            query_rot = Eigen::AngleAxisf(query_angle, query_normal.normalized());

            Eigen::Vector3f guess_r = query_rot * transformed_r;

            Eigen::Vector3f centroid_est = query.keypoints->at(i).getVector3fMap() - guess_r;

            Eigen::Vector3f region = query_max - query_min;
            Eigen::Vector3f bin_size = region / float (bins_);
            Eigen::Vector3f diff = (centroid_est - query_min);
            Eigen::Vector3f indices = diff.cwiseQuotient(bin_size);

            castVotes(indices, bins);
          }

        }

      }
    }
Example #9
0
	int query_min(int &p)
	{
		if(!L[p]) return A[p];
		return query_min(L[p]);
	}