上一页 1 ··· 3 4 5 6 7 8 9 10 下一页

并查集删除节点--虚节点

摘要: 在并查集中,往往两个集合合并很容易做到,但是要从一个集合中删除一点?需要开一个majia[]辅助数组,也就是意义上的马甲,披着马甲的节点,majia[I]=I是指I--->I,I映射到I,majia[I]=J是指I--->J是指I的当前父亲节点是Jvoid init(){ int i; for(i=0;i<n;i++) { parent[i]=i; majia[i]=i; }}int Find(int x){ return parent[x]!=x?parent[x]=Find(parent[x]):x;}void Union(int R1,... 阅读全文
posted @ 2013-07-16 15:20 张狂不年轻° 阅读(497) 评论(0) 推荐(0)

次小生成树HDU--4081

摘要: 刚接触的次小生成树,就是最小生成树通过一次变换得到。o(N^3)的做法: 求得最小生成树,标记其中的边,枚举删除每条边,再求最小生成树,并在这些权值中取得最小值,得到次小生成树。o(N^2)的做法: 先求得最小生成树,并在此中标记每条边是否用过。 mmax[I][J],数组来记录I到J最小生成... 阅读全文
posted @ 2013-07-16 09:30 张狂不年轻° 阅读(247) 评论(0) 推荐(0)

Map

摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 mapm; 9 m.insert(pair(1,"1234"));10 map::iterator ptr;11 m[2]="123";12 m.insert(map::value_type(3,"12")); //三种插入方式13 for(ptr=m.begin();ptr!=m.end();ptr++)14 {15 coutsecondsecond<<endl;... 阅读全文
posted @ 2013-07-12 16:48 张狂不年轻° 阅读(150) 评论(0) 推荐(0)

Set

摘要: 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 int main() 8 { 9 sets;10 s.insert(19);11 s.insert(20);12 s.insert(22);13 s.insert(25);14 set::iterator ptr;15 for(ptr=s.begin();ptr!=s.end();++ptr)16 {17 cout::iterator,set::iterator> p;25 p=... 阅读全文
posted @ 2013-07-12 15:54 张狂不年轻° 阅读(146) 评论(0) 推荐(0)

List

摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 listl; //创建一个空的list 9 l.assign(4,3); //分配值10 listL1;11 L1=l;12 cout::iterator ptr;15 for(ptr=l.begin();ptr!=l.end();++ptr)16 {17 cout());42 for(ptr=l.begin();ptr!=l.end... 阅读全文
posted @ 2013-07-12 15:18 张狂不年轻° 阅读(174) 评论(0) 推荐(0)

Priority_queue

摘要: priority_queue调用 STL里面的 make_heap(), pop_heap(), push_heap() 算法实现,也算是堆的另外一种形式。先写一个用 STL 里面堆算法实现的与真正的STL里面的 priority_queue用法相似的priority_queue, 以加深对 priority_queue 的理解。 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 class priority_queue 8 { 9 private:10 vector data;11... 阅读全文
posted @ 2013-07-12 14:18 张狂不年轻° 阅读(243) 评论(0) 推荐(0)

Stack

摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 stacks; 9 for(int i=0;i<5;i++)10 {11 s.push(i);12 }13 cout<<s.top()<<endl;14 cout<<s.size()<<endl;15 for(int i=0;i<5;i++)16 {17 s.pop();18 }19 cout<<s.size()<<endl;2... 阅读全文
posted @ 2013-07-12 14:00 张狂不年轻° 阅读(159) 评论(0) 推荐(0)

Queue

摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 queueQ; 9 cout<<Q.size()<<endl;10 for(int i=0;i<5;i++)11 {12 Q.push(i);13 }14 cout<<Q.front()<<endl;15 cout<<Q.back()<<endl;16 cout<<Q.empty()<<endl;17 for(int i=0;i<5;i 阅读全文
posted @ 2013-07-12 13:56 张狂不年轻° 阅读(178) 评论(0) 推荐(0)

Deque

摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 dequed; 9 for(int i=0;i::iterator ptr;14 for(ptr=d.begin();ptr!=d.end();ptr++)15 {16 coutd1;26 d1=d;27 for(ptr=d1.begin();ptr!=d1.end();ptr++)28 {29 cout<<*ptr<<" ";30 }31 ... 阅读全文
posted @ 2013-07-12 13:43 张狂不年轻° 阅读(121) 评论(0) 推荐(0)

Vector

摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 vectorv; 9 for(int i=0;i::iterator ptr; //智能指针,迭代器14 for(ptr=v.begin();ptr!=v.end();ptr++)15 {16 coutv1;25 v.swap(v1); //交换两个vector中的值26 for(ptr=v1.begin();ptr!=v1.end()... 阅读全文
posted @ 2013-07-12 13:15 张狂不年轻° 阅读(186) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 下一页