Пример #1
0
int query_max(int l,int r,int rt,int ll,int rr)
{
	if(l>=ll&&rr>=r)
	{
		return _max[rt];
	}
	
	int mid=(l+r)>>1;
	int tmp1=-0x7fffffff,tmp2=-0x7fffffff;
	if(ll<=mid) tmp1=query_max(l,mid,rt<<1,ll,rr);
	if(rr>mid) tmp2=query_max(mid+1,r,rt<<1|1,ll,rr);

	return (tmp1>tmp2)?tmp1:tmp2;
}
Пример #2
0
int query_max(int idx,int _l,int _r)
{//求_l到_r区间的最大值
	int max,max1;
	if(_l<=node[idx].l && _r>=node[idx].r)//如果覆盖这个区域 直接返回
		return node[idx].max;
	if(_r<=node[2*idx].r)
		{//返回左子树的最大值
			return query_max(2*idx,_l,_r);
		}
	else
		{
			if(_l>=node[2*idx+1].l)//返回右子树的最大值
				return query_max(2*idx+1,_l,_r);
			//返回左子树和右子树中最大值的最大值
			max=query_max(2*idx,_l,node[2*idx].r);
			max1=query_max(2*idx+1,node[2*idx+1].l,_r);
			if(max>max1)
				return max;
			else
				return max1;
		}
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
0
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;
}
Пример #6
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);
          }

        }

      }
    }
Пример #7
0
	int query_max(int &p)
	{
		if(!R[p]) return A[p];
		return query_max(R[p]);
	}