本文整理汇总了C++中priority_queue::pop方法的典型用法代码示例。如果您正苦于以下问题:C++ priority_queue::pop方法的具体用法?C++ priority_queue::pop怎么用?C++ priority_queue::pop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类priority_queue
的用法示例。
在下文中一共展示了priority_queue::pop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
//freopen("PAT1038.input", "r", stdin);
int N;
string a;
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> a;
int tmp = a.size();
a.resize(8);
for (int i = tmp; i < 8; i++)
a[i] = a[i-tmp];
que.push(MyString(a, tmp));
}
bool first = true;
while (!que.empty())
{
MyString a = que.top();
que.pop();
if (first)
{
// 陷阱:数字为0
int start = 0;
for (int i = 0; i < a.len; i++)
if (a.data[i] == '0')
start++;
else
break;
if (start == a.len)
continue;
a.len -= start;
first = false;
cout << a.data.substr(start, a.len);
}
else
cout << a.data.substr(0, a.len);
}
// 陷阱:如果所有数为0
if (first)
cout << 0;
cout << endl;
}
示例2: returnResults
/**
* @brief Return to the client the found results.
* @param rankedResults the ranked list of results.
* @param req the received search request.
* @param i_maxNbResults the maximum number of results returned.
*/
void ORBSearcher::returnResults(priority_queue<SearchResult> &rankedResults,
SearchRequest &req, unsigned i_maxNbResults)
{
list<u_int32_t> imageIds;
unsigned i_res = 0;
while(!rankedResults.empty()
&& i_res < i_maxNbResults)
{
const SearchResult &res = rankedResults.top();
imageIds.push_back(res.i_imageId);
i_res++;
cout << "Id: " << res.i_imageId << ", score: " << res.f_weight << endl;
req.results.push_back(res.i_imageId);
rankedResults.pop();
}
}
示例3: main
int main()
{
int n, m;
while(cin >> m >> n) {
if(n == 0 && m == 0) return 0;
adjlist.clear(); adjlist.resize(n);
int current = 0;
for(size_t i = 0; i < n; ++i) {
int x,y,z; cin >> x >> y >> z;
current += z;
adjlist[x].push_back(pair<int, int> (y, z));
adjlist[y].push_back(pair<int, int> (x, z));
}
taken.clear();
taken.resize(n, 0);
proccess(0);
int min_cost = 0;
while(!pq.empty()) {
pair<int, int> front = pq.top(); pq.pop();
int u = -front.second; // vertex
int w = -front.first; // weight
if(!taken[u]) {
min_cost += w;
taken[u] = 1;
for(int j = 0; j < adjlist[u].size(); ++j) {
pair<int, int> v = adjlist[u][j];
if(!taken[v.first])
pq.push(pair<int, int>(-v.second, -v.first)); // negate to handle negatives
}
}
}
cout << current - min_cost << endl;
}
return 0;
}
示例4: main
int main()
{
while(scanf("%d %d",&n,&m)!=EOF)
{
int i;
for(memset(deg,0,sizeof(deg)) , i=0;i<m;i++)
{
scanf("%d %d %d",&li[i][0],&li[i][1],&li[i][2]);
li[i][0]--;li[i][1]--; deg[li[i][0]]++; deg[li[i][1]]++;
}
for( i=0;i<n;e[i] = new(int[deg[i]]),c[i] = new(int[deg[i]]),deg[i]=0,i++);
for( i=0;i<m;i++)
{
e[li[i][0]][deg[li[i][0]]]=li[i][1];
c[li[i][0]][deg[li[i][0]]]=li[i][2];
deg[li[i][0]]++;
e[li[i][1]][deg[li[i][1]]]=li[i][0];
c[li[i][1]][deg[li[i][1]]]=li[i][2];
deg[li[i][1]]++;
}
struct dat dat2;
dat2.p=0;dat2.dis=0;
q.push(dat2);
int p,d;
for(memset(t,0,sizeof(t));!q.empty();q.pop())
{
p = q.top().p;
d=q.top().dis;
if(t[p]<2)
{
ans[p][t[p]]=d; t[p]++;
for(i=0;i<deg[p];i++)
{
if(t[e[p][i]]<2)
{
struct dat dat1 ;
dat1.p= e[p][i]; dat1.dis = d + c[p][i];
q.push(dat1);
}
}
}
}
printf("%d\n",ans[n-1][1]);
}
}
示例5: main
int main ()
{
int C, V, i, j, dest;
int u, v;
int C1, C2, G;
cin >> C >> V;
edge.clear();
edge.resize(2*C);
for (i = 0; i < V; i++)
{
cin >> C1 >> C2 >> G;
C1 = 2*(C1-1);
C2 = 2*(C2-1);
edge[C1].push_back(make_pair(C2+1,G));
edge[C2+1].push_back(make_pair(C1,G));
edge[C1+1].push_back(make_pair(C2,G));
edge[C2].push_back(make_pair(C1+1,G));
}
int dist[2*C];
dest = 2*C - 2;
for (i = 0; i < 2*C; i++)
dist[i] = INF;
dist[0] = 0;
q.push(make_pair(0,0));
while (!q.empty())
{
u = q.top().first;
q.pop();
int size = edge[u].size();
for (v = 0; v < size; v++)
{
int vv = edge[u][v].first;
int w = edge[u][v].second;
if (dist[u] + w < dist[vv])
{
dist[vv] = dist[u] + w;
q.push(make_pair(vv,dist[vv]));
}
}
}
if (dist[dest] == INF)
cout << -1 << endl;
else
cout << dist[dest] << endl;
}
示例6: Dijkstra
void Dijkstra(int src) {
dist = vector<int>(V+1, INF);
dist[src] = 0;
pq.push(make_pair(0, 1));
while (!pq.empty()) {
int cost = -pq.top().first;
int u = pq.top().second;
pq.pop();
if (cost > dist[u]) continue;
for (int i=0; i<adj[u].size(); ++i) {
int v = adj[u][i].first;
if (dist[v] > dist[u]+adj[u][i].second) {
dist[v] = dist[u]+adj[u][i].second;
pq.push(make_pair(-dist[v], v));
}
}
}
}
示例7: kruskall
double kruskall(int n) {
union_find ufds(n);
double mst_cost = 0.0;
while(not edges.empty()) {
auto current_edge = edges.top();
double w = current_edge.first;
int u = current_edge.second.first, v = current_edge.second.second;
if(not ufds.same_set(u, v)) {
ufds.union_set(u, v);
mst_cost += w;
}
edges.pop();
}
return mst_cost;
}
示例8: prim
int prim()
{
int ans = 0;
vector<Edge> mst;
visit(1);
while (!pq.empty() && mst.size()<N-1)
{
Edge e = pq.top();
pq.pop();
int u = e.either, v = e.other;
if (mark[u] && mark[v]) continue;
mst.push_back(e);
ans += e.weight;
if (!mark[u]) visit(u);
if (!mark[v]) visit(v);
}
return ans;
}
示例9: search
void search(){
for(int x = 0;x<MAX;x++) dist[x] = LARGE;
dist[1] = 0;
q.push(pii(0,1));
while(!q.empty()){
pii cur = q.top();
q.pop();
if(vis[cur.B]) continue;
vis[cur.B] = true;
for(vi it = list[cur.B].begin();it!=list[cur.B].end();++it){
if(dist[it->B]>dist[cur.B]+it->A){
pre[it->B] = cur.B;
dist[it->B] = dist[cur.B]+it->A;
q.push(pii(dist[it->B],it->B));
}
}
}
}
示例10: solve
int solve(priority_queue<int>& votes, int m) {
int count, n;
count = 0;
while (votes.size() > 0) {
n = votes.top();
votes.pop();
if (n < m) break;
votes.push(--n);
m++;
count++;
}
return count;
}
示例11: main
int main(void) {
string s;
int q, p, k;
while(cin >> s, s!="#") {
cin >> q >> p;
Q.push(Item(q, p));
}
cin >> k;
for(int i=0; i<k; ++i) {
Item item = Q.top(); Q.pop();
cout << item.q << endl;
Q.push(item.next());
}
return 0;
}
示例12: dijkstra
double dijkstra(int st, int ed) {
for (int i = 0; i < n; i++)
dis[i] = inf, vis[i] = false;
dis[st] = 0;
q.push(MP(0.0, st));
while (!q.empty()) {
int u = q.top().second; q.pop();
vis[u] = true;
for (int i = last[u]; ~i; i = prev[i]) {
int v = to[i];
if (!vis[v] && sig(dis[v] - (dis[u] + len[i])) > 0) {
dis[v] = dis[u] + len[i];
q.push(MP(-dis[v], v));
}
}
}
return dis[ed];
}
示例13: dijkstra
void dijkstra(){
int u, v, d1, d2, currStatus;
u = 0, d1 = 0, currStatus = walk;
dist[currStatus][0] = 0;
pq.push(iii(dist[currStatus][0], 0, currStatus));
while(!pq.empty()){
tie(d1, u, currStatus) = pq.top(); pq.pop();
if(d1 > dist[currStatus][u]) continue;
for(int i = 0; i < AdjList[u].size(); ++i){
v = AdjList[u][i].first, d2 = AdjList[u][i].second;
if(d1 + d2 < dist[1 - currStatus][v]){
dist[1 - currStatus][v] = d1 + d2;
pq.push(iii(dist[1 - currStatus][v], v, 1 - currStatus));
}
}
}
}
示例14: dijkstra
void dijkstra(int source, vector<int> &dist, vector< vector< ii > > &AdjList){
dist[source] = 0;
pq.push(ii(dist[source], source));
int u, v, d1, d2;
while(!pq.empty()){
u = pq.top().second; d1 = pq.top().first;
pq.pop();
if(d1 > dist[u]) continue;
for(int i = 0; i < AdjList[u].size(); ++i){
v = AdjList[u][i].first; d2 = AdjList[u][i].second;
if(d1 + d2 < dist[v]){
dist[v] = d1 + d2;
pq.push(ii(dist[v], v));
}
}
}
}
示例15: main
int main(int argc, char *argv[])
{
scanf("%d%d%d",&n,&e,&k);
for(int i = 1;i<=k;i++)
scanf("%d%d%d",&h[i].x,&h[i].f,&h[i].c);
sort(h+1,h+k+1);
st s;
s.i = 0;s.key = 0;s.n = 0;
q.push(s);
for(int i = 1;i<=k;i++)
{
while(!q.empty() && q.top().i < i-1)
q.pop();
}
system("PAUSE");
return EXIT_SUCCESS;
}