本文整理汇总了C++中PQ::size方法的典型用法代码示例。如果您正苦于以下问题:C++ PQ::size方法的具体用法?C++ PQ::size怎么用?C++ PQ::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PQ
的用法示例。
在下文中一共展示了PQ::size方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dijdij
int dijdij(int st,int ed){
v[0].reset(); v[1].reset();
for(int i=0;i<111;++i)d[i].clear();
d[st].pb(0);
PQ<pii,vector<pii>,greater<pii>> pq; pq.push({0,st});
while(pq.size()){
while(pq.size() && v[1][pq.top().Y])pq.pop();
if(pq.empty())break;
pii now=pq.top(); pq.pop();
int stp=v[0][now.Y]?1:0;
PDE3(now,stp,pq);
v[stp][now.Y]=1;
for(pii e:G[now.Y]){
d[e.X].pb(now.X+e.Y);
sort(d[e.X].begin(),d[e.X].end());
d[e.X].resize(unique(d[e.X].begin(),d[e.X].end())-d[e.X].begin());
if(d[e.X].size()>2u){
sort(d[e.X].begin(),d[e.X].end());
d[e.X].pop_back();
}
if(now.X+e.Y<=d[e.X].back()){
pq.push({now.X+e.Y,e.X});
}
}
}
if(d[ed].size()<2u)return -1;
else return d[ed][1];
}
示例2: testHeap
void testHeap ( int n ) {
T* A = new T[2*n/3]; //创建容量为2*n/3的数组,并
for ( int i = 0; i < 2 * n / 3; i++ ) A[i] = dice ( ( T ) 3 * n ); //在其中随机生成2*n/3个词条
/*DSA*/printf ( "%d random keys created:\n", 2 * n / 3 );
/*DSA*/for ( int i = 0; i < 2 * n / 3; i++ ) print ( A[i] ); printf ( "\n" );
PQ heap ( A + n / 6, n / 3 ); //批量建堆(PQ_ComplHeap实现了Robert Floyd算法)
delete [] A;
/*DSA*/system("cls"); print ( heap ); Sleep(100);
while ( heap.size() < n ) { //随机测试
if ( dice ( 100 ) < 70 ) { //70%概率插入新词条
T e = dice ( ( T ) 3 * n ); /*DSA*/printf ( "Inserting" ); print ( e ); printf ( " ...\n" );
heap.insert ( e ); /*DSA*/printf ( "Insertion done\n" );
} else { //30%概率摘除最大词条
if ( !heap.empty() ) {
/*DSA*/printf ( "Deleting max ...\n" );
T e = heap.delMax();/*DSA*/printf ( "Deletion done with" ); print ( e ); printf ( "\n" );
}
}
/*DSA*/system("cls"); print ( heap ); Sleep(100);
}
while ( !heap.empty() ) { //清空
T e = heap.delMax();/*DSA*/printf ( "Deletion done with" ); print ( e ); printf ( "\n" );
/*DSA*/system("cls"); print ( heap ); Sleep(100);
}
}
示例3: main
int main(){
int n,m; cin>>n>>m;
while(m--){
int u,v; ll c; cin>>u>>v>>c;
pq.push({c,pii(u,v)});
E.eb(c,pii(u,v));
}
djs.init(1006);
int pointsssss=1;
ll firstttttt=0;
while(pq.size()){
if(!djs.C(pq.top().Y.X,pq.top().Y.Y)){
G[pq.top().Y.X].eb(pq.top().Y.Y,pq.top().X);
G[pq.top().Y.Y].eb(pq.top().Y.X,pq.top().X);
++pointsssss;
firstttttt+=pq.top().X;
djs.U(pq.top().Y.X,pq.top().Y.Y);
} pq.pop();
} if(pointsssss<n)return cout<<"-1 -1"<<endl,0;
if(E.size()==n-1)return cout<<firstttttt<<" -1"<<endl,0;
dfs(1,1,1);
PDE1(firstttttt);
ll diffffffff=1000000000000000000ll;
for(auto i:E){
if(p[0][i.Y.X]==i.Y.Y || p[0][i.Y.Y]==i.Y.X)continue;
PDE1(i);
diffffffff=min(diffffffff,i.X-lca(i.Y.X,i.Y.Y));
} cout<<firstttttt<<" "<<firstttttt+diffffffff<<endl;
}
示例4: find_top_CC
// find top-k CC using boost graph representation
PQ find_top_CC(DeterministicGraph& PW, int k) {
typename graph_traits <DeterministicGraph>::out_edge_iterator out1, out2;
PQ pq; // priority queue for top-k CC
int V = num_vertices(PW);
bool *explored = new bool[V+1];
for (int i = 0; i < V; ++i)
explored[i] = false;
int cc_number = 0;
int unit_sized = 0;
for (int i = 0; i < V; ++i) {
if (!explored[i]) {
// perform BFS for vertex i
vector<int> CC;
CC.push_back(i);
explored[i] = true;
vector<int>::size_type ix = 0;
while (ix < CC.size()) {
Vertex u = vertex(CC[ix], PW);
for (tie(out1, out2) = out_edges(u, PW); out1 != out2; ++out1) {
Vertex v = target(*out1, PW);
if (!explored[v]) {
CC.push_back(v);
explored[v] = true;
}
}
ix++;
}
// if (CC.size() > 5)
// cout << cc_number << ": " << CC.size() << endl;
if (CC.size() == 1) {
unit_sized++;
}
cc_number++;
// maintain CC priority queue
int pq_size = pq.size();
if (pq_size == k) {
vector<int> top = pq.top();
if (top.size() < CC.size()) {
pq.pop();
pq.push(CC);
}
}
else
pq.push(CC);
}
}
// cout << "Total CCs: " << cc_number << endl;
// cout << "Unit CCs: " << unit_sized << endl;
return pq;
}
示例5: find_top_CC2
// find top-k CCs using vectors graph representation
PQ find_top_CC2(vector<vector<int> >& PW, int V, int k) {
PQ pq; // priority queue for top-k CC
map<int, bool> explored;
for (int i = 0; i < V; ++i)
explored[i] = false;
int cc_number = 0;
int unit_sized = 0;
for (int i = 0; i < V; ++i) {
if (!explored[i]) {
// perform BFS for vertex i
vector<int> CC;
CC.push_back(i);
explored[i] = true;
vector<int>::size_type ix = 0;
while (ix < CC.size()) {
int pw_size = PW[CC[ix]].size();
for (int j = 0; j < pw_size; ++j) {
int v = PW[CC[ix]][j];
if (!explored[v]) {
CC.push_back(v);
explored[v] = true;
}
}
ix++;
}
// if (CC.size() > 5)
// cout << cc_number << ": " << CC.size() << endl;
if (CC.size() == 1) {
unit_sized++;
}
cc_number++;
// maintain CC priority queue
int pq_size = pq.size();
if (pq_size == k) {
vector<int> top = pq.top();
if (top.size() < CC.size()) {
pq.pop();
pq.push(CC);
}
}
else
pq.push(CC);
}
}
// cout << "Total CCs: " << cc_number << endl;
// cout << "Unit CCs: " << unit_sized << endl;
return pq;
}
示例6: main
int main(){
// freopen("in","r",stdin);
// freopen("out","w",stdout);
int ks=0,n,m;while(rit(n,m),n){
while(m--){
int a,b,l;rit(a,b,l);
G[a].pb({b,l}); G[b].pb({a,l});
}
pq.push({1,0});
while(pq.size()){
while(v[pq.top().X])pq.pop();
v[pq.top().X]=1;
}
}
}
示例7: size
/*!
Returns the current size of the queue
\return Size
*/
int size(){ return pq.size(); }