当前位置: 首页>>代码示例>>C++>>正文


C++ priority_queue::size方法代码示例

本文整理汇总了C++中std::priority_queue::size方法的典型用法代码示例。如果您正苦于以下问题:C++ priority_queue::size方法的具体用法?C++ priority_queue::size怎么用?C++ priority_queue::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::priority_queue的用法示例。


在下文中一共展示了priority_queue::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: insert

void Median::insert(int value)
{
   size_t l = maxHeap1.size();
   size_t m = minHeap2.size();
   if (l - m == 0) {
      if (l != 0 && value > maxHeap1.top()) {
         minHeap2.push(value);
      } else {
         maxHeap1.push(value);
      }
   } else if (labs(l - m) == 1) {
      if (l > m) {
         if (maxHeap1.top() > value) {
            int r = maxHeap1.top();
            maxHeap1.pop();
            minHeap2.push(r);
            maxHeap1.push(value);
         } else {
            minHeap2.push(value);
         }
      } else {
         if (minHeap2.top() < value) {
            int r = minHeap2.top();
            minHeap2.pop();
            maxHeap1.push(r);
            minHeap2.push(value);
         } else {
            maxHeap1.push(value);
         }
      }
   }
}
开发者ID:mnv104,项目名称:hackerrank,代码行数:32,代码来源:median.cpp

示例2: getMedian

double getMedian(const std::priority_queue<double, std::vector<double>, std::greater<double> >& m,
		const std::priority_queue<double>& M){

	if(m.size() > M.size()) // There are an odd number of observations
		return m.top();
	else if(M.size() > m.size()) // There are an odd number of observations
		return M.top();
	else // There are an even number of obersations
		return (m.top()+M.top())/2;
}
开发者ID:Intellifora,项目名称:BreakoutDetection,代码行数:10,代码来源:edmx.cpp

示例3: pushBoundedPriorityQueue

//Maintains the size of the priority queue at the specified size bound with each push
//For now this function is for priority queue that is in ascending order, top is smallest.
//Returns result: 0 if not added, 1 if pushed without pop, 2 if pushed & popped
int pushBoundedPriorityQueue(std::priority_queue<int, std::vector<int>, std::greater<int> >  &pq,
                              int element, long bound)
{
   int result = 0;
   if(pq.size() < bound || element > pq.top()){
      pq.push(element);
      result = 1;
      if(pq.size() > bound){
         pq.pop();
         result = 2;
      }
   }
   return result;
}
开发者ID:thekingtat,项目名称:largest-n-integers,代码行数:17,代码来源:LargestMIntegersScript.cpp

示例4: main

int main(void)
{
    while(scanf("%d", &numbers) != -1 && numbers)
    {
        result = 0;
        for(int n = 0; n < numbers; ++ n)
        {
            scanf("%d", &number);
            que.push(number);
        }

        while(que.size() > 1)
        {
            int first = que.top(); que.pop();
            int second = que.top(); que.pop();
            que.push(first + second);
            result += first + second;
        }

        que.pop();
        printf("%lld\n", result);
    }

    return 0;
}
开发者ID:Neverous,项目名称:ii-mia,代码行数:25,代码来源:addition.cpp

示例5: expand

int expand()
{
    Nodes node= nodes.top();
   
    if(nodes.size()==0)
    {
             cout<<"error";
             getch();
             return 0;
    }                  
    nodes.pop();
    if(visited[node.node]==1)
         return 0;
    else 
         visited[node.node]=1;
         
    if(node.node==end)
    {
       cout<<"Minimum delay from source to destination device:"<<node.cost;
       return 1;
    }
    else
    {
        for(int j=0;j<n;j++)
        {
           if(a[j][node.node]!=0)
           {
                nodes.push(Nodes(j,node.cost+a[j][node.node]));
           }
        }    
        
    }
   return 0;
}
开发者ID:LakshmiPraneetha,项目名称:Learning-Stairs,代码行数:34,代码来源:pizzadelevery.cpp

示例6: expand

int expand()
{
    Nodes node= nodes.top();
    getch();
    if(nodes.size()==0)
    {
             cout<<"error";
             getch();
             return 0;
    }                  
    nodes.pop();
    if(visited[node.node]==1)
         return 0;
    else 
         visited[node.node]=1;
         
    if(node.node==end)
    {
       cout<<"finalcost"<<node.cost;
       return 1;
    }
    else
    {
        for(int j=0;j<n;j++)
        {
           if(a[j][node.node]!=0)
           {
                nodes.push(Nodes(j,node.cost+a[j][node.node]));
           }
        }    
        
    }
   return 0;
}
开发者ID:LakshmiPraneetha,项目名称:Learning-Stairs,代码行数:34,代码来源:uniformsearch.cpp

示例7: getMedian

double Median::getMedian(void)
{
   size_t l = maxHeap1.size();
   size_t m = minHeap2.size();
   if (l == 0 && m == 0) {
      throw std::invalid_argument("No elements inserted yet");
   }
   if (l - m == 0) {
      return (maxHeap1.top() + minHeap2.top()) / 2.0;
   } else {
      if (l > m) {
         return maxHeap1.top();
      } else {
         return minHeap2.top();
      }
   }
}
开发者ID:mnv104,项目名称:hackerrank,代码行数:17,代码来源:median.cpp

示例8: pushPriorityQueueBounded

//Maintains the size of the priority queue at the specified size with each push
//For now this function is for priority queue that is in ascending order, top is smallest.
void pushPriorityQueueBounded(std::priority_queue<int, std::vector<int>, std::greater<int> >  &pq,
                              int newElement, unsigned long priorityQueueBound)
{
   if(pq.empty() || newElement > pq.top())
      pq.push(newElement);
   if(pq.size() > priorityQueueBound)
      pq.pop();
}
开发者ID:thekingtat,项目名称:largest-n-integers,代码行数:10,代码来源:LargestMIntegersVS.cpp

示例9: UCS

void UCS()
{
     int check=0;
     nodes.push(Nodes(start,0));
     visited[start]=0;
     cout<<nodes.size();
     while(check==0) 
     check=expand();
}
开发者ID:LakshmiPraneetha,项目名称:Learning-Stairs,代码行数:9,代码来源:uniformsearch.cpp

示例10: updataQ

// Update the Queue. If the queue size less than K, just push.
// Otherwise, if the new value less than the max value, delete the max
// and push new node into queue.
void updataQ(std::priority_queue<Node>& q, RealT d, int i){
  if(q.size() < K) q.push(Node(i,d));
  else{
    if(q.top().dis > d){
      q.pop();
      q.push(Node(i,d));
    }
  }
}
开发者ID:xymajy,项目名称:865datamining,代码行数:12,代码来源:Knnexact_notime.cpp

示例11: AddToHeaps

void AddToHeaps(std::priority_queue<double, std::vector<double>, std::greater<double> >& m,
		std::priority_queue<double>& M, double x){

	// decide on initial heap to place element into
	if(m.empty() || x < m.top())
		M.push(x);
	else
		m.push(x);
	// make sure that heaps are balanced
	if(m.size() > M.size() + 1){
		M.push( m.top() );
		m.pop();	
	}
	else if(M.size() > m.size() + 1){
		m.push( M.top() );
		M.pop();
	}
}
开发者ID:Intellifora,项目名称:BreakoutDetection,代码行数:18,代码来源:edmx.cpp

示例12: checkCollision

void checkCollision() {
    int i, j;
    if ( events.size()!=0) {
        while( elapsedTime >= events.top().timeOccuring)
        {
            i = events.top().i;

            if( checkOutdated( events.top() ) ) {
                printf("---POOPZIES of %d, timeInserted=%f, lastCollition=%f\n",
                       i, events.top().timeInserted, sphere[i].lastCollision );
                events.pop();
            } else if (events.top().j!=-1) {
                j = events.top().j;

                sphere[i].q0 += (events.top().timeOccuring - sphere[i].t0) * sphere[i].speedVec;
                sphere[i].speedVec = sphere[i].newSpeedVec;
                sphere[i].t0 = events.top().timeOccuring;

                sphere[j].q0 += (events.top().timeOccuring - sphere[j].t0) * sphere[j].speedVec;
                sphere[j].speedVec = sphere[j].newSpeedVec;
                sphere[j].t0 = events.top().timeOccuring;

                sphere[i].cols++;
                sphere[j].cols++;

                events.pop();
                calculateCollision(i);
                calculateCollision(j);
                printf("BALLZIES of %d, timeInserted=%f, lastCollition=%f\n",
                       i, events.top().timeInserted, sphere[i].lastCollision );
            } else {
                sphere[i].q0 += (events.top().timeOccuring - sphere[i].t0) * sphere[i].speedVec;
                sphere[i].speedVec = sphere[i].newSpeedVec;
                sphere[i].t0 = events.top().timeOccuring;

                sphere[i].cols++;

                events.pop();
                calculateCollision(i);
                printf("WALLZIES of %d, timeInserted=%f, lastCollition=%f\n",
                       i, events.top().timeInserted, sphere[i].lastCollision );
            }
        }
        //std::vector<Sphere>::iterator it = sphereIterInit;
        //for(it; it != sphere.end();it++){
        //	position = it->q0 + (float)(elapsedTime - it->t0) * it->speedVec;
        //	if(abs(position.x)>0.96f || abs(position.y)>0.96f || abs(position.z)>0.96f){
        //		printf("WHAT THE FUCK MOAR BUGS PLS!!!!!AAAAAAAAAAARRGGH\n");
        //	}
        //}


        minmin = (events.top().timeOccuring<minmin)?events.top().timeOccuring:minmin;
    }
}
开发者ID:sespiros,项目名称:ceid-projects,代码行数:55,代码来源:OLD+LOOP.cpp

示例13: pop_front

	bool pop_front(T& data)
	{
		std::lock_guard<std::mutex> guard(mtx);
		if (pq.size() > 1)
		{
			data = pq.top();
			pq.pop();
			return true;
		}
		return false;
	};
开发者ID:renato2099,项目名称:ParallelPriorityQueue,代码行数:11,代码来源:ppq_std.hpp

示例14: main

int main()
{
	scanf( "%d", &N );
	REP(i, N)
	{
		int x;
		scanf( "%d", &x );
		pq.push(x);
		while (pq.size() > N / 2 + 1)
		      pq.pop();
	}
开发者ID:kantlove,项目名称:ProgrammingContests,代码行数:11,代码来源:1306.nlgn.cpp

示例15: search

	// Helper function that searches the tree    
	void search(Node* node, const T& target, int k, std::priority_queue<HeapItem>& heap)
	{
		if(node == NULL) return;     // indicates that we're done here

		// Compute distance between target and current node
		ScalarType dist = distance(_items[node->index], target);

		// If current node within radius tau
		if(dist < _tau) {
			if(heap.size() == static_cast<size_t>(k)) heap.pop(); // remove furthest node from result list (if we already have k results)
			heap.push(HeapItem(node->index, dist));           // add current node to result list
			if(heap.size() == static_cast<size_t>(k)) _tau = heap.top().dist;     // update value of tau (farthest point in result list)
		}

		// Return if we arrived at a leaf
		if(node->left == NULL && node->right == NULL) {
			return;
		}

		// If the target lies within the radius of ball
		if(dist < node->threshold) {
			if(dist - _tau <= node->threshold) {         // if there can still be neighbors inside the ball, recursively search left child first
				search(node->left, target, k, heap);
			}

			if(dist + _tau >= node->threshold) {         // if there can still be neighbors outside the ball, recursively search right child
				search(node->right, target, k, heap);
			}

			// If the target lies outsize the radius of the ball
		} else {
			if(dist + _tau >= node->threshold) {         // if there can still be neighbors outside the ball, recursively search right child first
				search(node->right, target, k, heap);
			}

			if (dist - _tau <= node->threshold) {         // if there can still be neighbors inside the ball, recursively search left child
				search(node->left, target, k, heap);
			}
		}
	}
开发者ID:ConfusedReality,项目名称:pkg_machine-learning_tapkee,代码行数:41,代码来源:vptree.hpp


注:本文中的std::priority_queue::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。