本文整理汇总了C++中PriorityQueue::remove方法的典型用法代码示例。如果您正苦于以下问题:C++ PriorityQueue::remove方法的具体用法?C++ PriorityQueue::remove怎么用?C++ PriorityQueue::remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue::remove方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
ios::sync_with_stdio(false);
ll n, idx = 0, val, rs; cin >> n;
Node nd; cin >> nd.x >> nd.y;
val = nd.x, nd.diff = nd.y - nd.x + 1, Score.push_back(nd);
for (int i = 1; i < n; i++){
cin >> nd.x >> nd.y;
nd.diff = nd.y - nd.x + 1;
if (nd.x > val) idx++;
Score.push_back(nd);
}
rs = idx;
sort(all(Score), cmp);
PriorityQueue pq;
int lstidx = idx + 1;
for (int i = 0; i < idx; i++){
pq.add(Score[i].diff);
}
while (val >= pq.top()){
if (!rs || pq.top() == -1) break;
if (pq.top() <= val){
val -= pq.top();
pq.remove();
idx--;
}
while (lstidx < n && Score[lstidx].x > val){
pq.add(Score[lstidx].diff);
lstidx++;
idx++;
}
rs = min(rs, idx);
}
cout << rs + 1 << ln;
return 0;
}
示例2: main
int main( )
{
PriorityQueue q;
q.add("Joi"); // Added to the front/back of the queue
q.add("Gudrun", 5); // Added to the front of the queue
q.add("Gummi", 7); // Added to the front of the queue
q.add("Sigga", 3); // Added to the next to back of the queue
q.add("Magga"); // Added to the back of the queue
for (int i=1; i<=5; i++)
{
removed = q.remove();
cout << removed << " was removed" << endl;
}
removed = q.remove();
cout << removed << " was removed" << endl;
return 0;
}
示例3: main
int main() {
PriorityQueue<string> q;
q += "a";
q += "c";
q += "b";
try{
cout << q.remove() << endl;
cout << q.remove() << endl;
cout << q.remove() << endl;
cout << q.remove() << endl;
}catch(range_error e){
cout << e.what() << endl;
}
return 0;
}
示例4: getOptimalPath
int* getOptimalPath(Vertex Graph[], int size, int start, int goal)
{
PriorityQueue<float> PQ;
LinkedList<edge>* Edges;
int current, next, i;
float NewCost;
float *CostSoFar = new float[size];
for (i = 1; i < size; i++)
CostSoFar[i] = FLT_MAX;
CostSoFar[0] = 0.0;
int* parent = new int[size];
//PQ.insert(start, getEuclideanDistance(Coordinates[start], Coordinates[goal]));
PQ.insert(start, 0);
while (!PQ.isEmpty())
{
//PQ.Print();
current = PQ.remove();
if (current == goal)
{
delete [] CostSoFar;
return parent;
}
else
{
Edges = &Graph[current].getEdges();
for (Edges->begin(); !Edges->end(); Edges->next())
{
next = Edges->getCurrent().to;
NewCost = CostSoFar[current] + Edges->getCurrent().cost /*+ getEuclideanDistance(Coordinates[next], Coordinates[goal])*/;
if (NewCost < CostSoFar[next])
{
CostSoFar[next] = NewCost;
parent[next] = current;
PQ.insert(next, NewCost);
}
}
}
}
delete [] CostSoFar;
return NULL;
}