本文整理汇总了C++中std::priority_queue::push方法的典型用法代码示例。如果您正苦于以下问题:C++ priority_queue::push方法的具体用法?C++ priority_queue::push怎么用?C++ priority_queue::push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::priority_queue
的用法示例。
在下文中一共展示了priority_queue::push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dijkstra
void dijkstra() {
std::fill(d + 1, d + n + 1, INF);
for (int i = 1; i <= n; i++) {
if (!w[i]) continue;
heap.push((Heapnode){d[i] = 0, i});
}
while (!heap.empty()) {
Heapnode top = heap.top(); heap.pop();
if (v[top.node]) continue;
v[top.node] = true;
for (int i = h[top.node]; i; i = e[i].next)
if (!v[e[i].node] && d[e[i].node] > top.dist + e[i].dist) {
d[e[i].node] = top.dist + e[i].dist;
p[e[i].node] = top.node;
heap.push((Heapnode){d[e[i].node], e[i].node});
}
}
s = 0;
for (int i = 1, cnt = 0; i <= n; i++) {
if (!w[i]) continue;
c[i] = ++s;
}
for (int i = 1; i <= n; i++) {
if (w[i]) continue;
fa[getfa(i)] = getfa(p[i]);
}
for (int i = 1; i <= n; i++) {
if (w[i]) continue;
c[i] = c[getfa(i)];
}
}
示例2: explore
// -------------------------------------------------------------------------
void GraphDefinition::explore(
int cur_node,
GraphEdgeInfo& cur_edge,
bool isStart,
LongVector &vecIndex,
std::priority_queue<PDP, std::vector<PDP>,
std::greater<PDP> > &que)
{
unsigned int i;
double extCost = 0.0;
GraphEdgeInfo* new_edge;
// int new_node;
double totalCost;
for(i = 0; i < vecIndex.size(); i++)
{
new_edge = m_vecEdgeVector[vecIndex[i]];
extCost = 0.0;
if(m_bIsturnRestrictOn)
{
extCost = getRestrictionCost(cur_edge.m_lEdgeIndex, *new_edge, isStart);
}
if(new_edge->m_lStartNode == cur_node)
{
if(new_edge->m_dCost >= 0.0)
{
//new_node = new_edge->m_lEndNode;
if(isStart)
totalCost = m_dCost[cur_edge.m_lEdgeIndex].endCost + new_edge->m_dCost + extCost;
else
totalCost = m_dCost[cur_edge.m_lEdgeIndex].startCost + new_edge->m_dCost + extCost;
if(totalCost < m_dCost[vecIndex[i]].endCost)
{
m_dCost[vecIndex[i]].endCost = totalCost;
parent[new_edge->m_lEdgeIndex].v_pos[0] = (isStart?0:1);
parent[new_edge->m_lEdgeIndex].ed_ind[0] = cur_edge.m_lEdgeIndex;
que.push(std::make_pair(totalCost, std::make_pair(new_edge->m_lEdgeIndex, true)));
}
}
}
else
{
if(new_edge->m_dReverseCost >= 0.0)
{
// new_node = new_edge->m_lStartNode;
if(isStart)
totalCost = m_dCost[cur_edge.m_lEdgeIndex].endCost + new_edge->m_dReverseCost + extCost;
else
totalCost = m_dCost[cur_edge.m_lEdgeIndex].startCost + new_edge->m_dReverseCost + extCost;
if(totalCost < m_dCost[vecIndex[i]].startCost)
{
m_dCost[vecIndex[i]].startCost = totalCost;
parent[new_edge->m_lEdgeIndex].v_pos[1] = (isStart?0:1);
parent[new_edge->m_lEdgeIndex].ed_ind[1] = cur_edge.m_lEdgeIndex;
que.push(std::make_pair(totalCost, std::make_pair(new_edge->m_lEdgeIndex, false)));
}
}
}
}
}
示例3: main
int main() {
freopen("F.in", "r", stdin);
while (scanf("%d%d", &n, &m) == 2 && n && m) {
for (int i = 1; i <= n; i++) {
scanf("%s", map[i] + 1);
}
scanf("%d%d", &sx, &sy);
scanf("%d%d", &ex, &ey);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
v[i][j] = false;
d[i][j] = INF;
}
heap.push(std::make_pair(d[sx][sy] = 0, std::make_pair(sx, sy)));
while (!heap.empty()) {
std::pair<int, std::pair<int, int> > top = heap.top(); heap.pop();
if (v[top.second.first][top.second.second]) continue;
v[top.second.first][top.second.second] = true;
for (int dir = 0; dir < 4; dir++) {
int nx = top.second.first + dx[dir];
int ny = top.second.second + dy[dir];
if (nx < 1 || nx > n || ny < 1 || ny > m) continue;
int cost = map[nx][ny] == '.';
if (!v[nx][ny] && d[nx][ny] > d[top.second.first][top.second.second] + cost) {
d[nx][ny] = d[top.second.first][top.second.second] + cost;
heap.push(std::make_pair(d[nx][ny], std::make_pair(nx, ny)));
}
}
}
printf("%d\n", d[ex][ey]);
}
return 0;
}
示例4: main
int main(void)
{
scanf("%u %u", &words, &maxLength);
for(unsigned int w = 0; w < words; ++ w)
{
scanf("%s", word);
sWord[w] = std::string(word);
que.push(sWord[w]);
}
while(!que.empty() && que.top().length() <= maxLength)
{
act = que.top();
que.pop();
if(isPalindrome(act))
{
++ result;
if(result == 835454957)
result = 0;
}
for(unsigned int w = 0; w < words; ++ w)
que.push(act + " " + sWord[w]);
}
printf("%u\n", result);
return 0;
}
示例5: 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;
}
示例6: 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));
}
}
}
示例7: rearrange
void rearrange(Attributes *attr, TWeight score)
{
AttrsPtr a;
while ((a = opened.top()), opened.pop(), (a.pa != attr)) temp_buff.push_back(a);
a.pa->fscore = score;
opened.push(a);
while (!temp_buff.empty())
{
opened.push(temp_buff.back());
temp_buff.pop_back();
}
}
示例8: 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);
}
}
}
}
示例9: main
int main()
{
for(scanf("%d",&n);i<n;i++)
scanf("%d",a+i);
for(i=0;i<n;i++)
scanf("%d",b+i);
std::sort(a,a+n);
std::sort(b,b+n);
for(i=0;i<n;i++){
q.push((S){a[i]+b[0],0});
printf("%d ",(t=q.top()).s);
q.pop();
if(t.b<n)
q.push((S){t.s-b[t.b]+b[t.b+1],t.b+1});
}
}
示例10: make_pair
/**
* Moves a board in all the possible directions and adds the new states to the queue.
* @param board The board to be moved.
* @param queue The priority queue holding all board states.
*/
std::pair<bool, Board*> MoveAllDirectionsAndAddToQueue(Board* &board,
std::priority_queue<Board*, std::vector<Board*>, QueueCompareClass> &queue) {
// For all 4 directions, try to move in that direction.
for (unsigned int i = 0; i < 4; ++i) {
int direction = DIRECTIONS[i];
// If the board can move in that direction, then move it.
// If it can't, then do nothing.
if (CanMoveInDirection(direction, board)) {
// Create a copy of the current board, and move the copy.
Board* new_board = new Board(*board);
// Actually move the board.
MoveInDirection(direction, new_board);
// Set the previous board state.
new_board->SetPreviousState(board);
// Check if the board is at the goal state, if so then stop.
if (new_board->IsAtGoalState()) {
return std::make_pair(true, new_board);
}
// Do not add the new state to the queue if the new board is the
// same as the previous state.
if (board->GetPreviousState() &&
*(board->GetPreviousState()) == *new_board) {
delete new_board;
new_board = NULL;
} else {
queue.push(new_board);
}
}
}
return std::make_pair(false, reinterpret_cast<Board*>(NULL));
}
示例11: enqueue
void enqueue(map_t* map, unsigned int i, unsigned int j,
unsigned int src_i, unsigned int src_j,
std::priority_queue<CellData>& Q,
CachedDistanceMap* cdm,
unsigned char* marked)
{
if(marked[MAP_INDEX(map, i, j)])
return;
unsigned int di = abs(i - src_i);
unsigned int dj = abs(j - src_j);
double distance = cdm->distances_[di][dj];
if(distance > cdm->cell_radius_)
return;
map->cells[MAP_INDEX(map, i, j)].occ_dist = distance * map->scale;
CellData cell;
cell.map_ = map;
cell.i_ = i;
cell.j_ = j;
cell.src_i_ = src_i;
cell.src_j_ = src_j;
Q.push(cell);
marked[MAP_INDEX(map, i, j)] = 1;
}
示例12: 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;
}
示例13: 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;
}
示例14: readAlignment
/**
* decode next alignment
*
* @param algn reference to alignment object to be filled
* @return true iff next alignment could be read, false when no more alignments are available
**/
bool readAlignment(libmaus::bambam::BamAlignment & algn)
{
if ( Q.empty() )
return false;
uint64_t const t = Q.top();
Q.pop();
libmaus::bambam::BamAlignment::D_array_type T = algn.D;
algn.D = data[t].D;
algn.blocksize = data[t].blocksize;
data[t].D = T;
data[t].blocksize = 0;
if ( index[t].second-- )
{
#if !defined(NDEBUG)
bool const alok =
#endif
libmaus::bambam::BamDecoder::readAlignmentGz(*(streams[t]),data[t],0,false);
#if !defined(NDEBUG)
assert ( alok );
#endif
Q.push(t);
}
return true;
}
示例15: scheduleFixedInterval
shared_ptr<RunItem> scheduleFixedInterval(std::function<void()> task, chrono::steady_clock::duration delay) {
shared_ptr<RunItem> retval(new RunItem(task, delay, true));
lock_guard<mutex> lock(m);
delayworkqueue.push(retval);
cv.notify_one();
return retval;
}