摘要: 1.dist[n]并不是记录该最小生成树的最小权值2.两个for(j)循环的意义不一样,第一个是寻找与k点相邻的最小边,第二个是更新与k点相邻的边,当然dist依旧会存储着以前点k‘响铃的边,比如说第一个初始化的循环,第一个dist存储这与起点相邻的边,而这些边一次性用不完。http://sjjg.... 阅读全文
posted @ 2012-08-07 10:28 calmound 阅读(224) 评论(0) 推荐(0) 编辑
摘要: #include#includeconst int MAXN=10000010;int father[MAXN],hash[MAXN];void Make_set(){ for(int i=0;irank[y]) father[y]=x; else { if(rank... 阅读全文
posted @ 2012-08-07 09:12 calmound 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 判断树是否唯一1.只有一个根节点,(1)在一棵树上一个根节点。1 2 3 2就是两个根节点(1)只有一棵树2.不成环,入度不大于1由于数组运行超界导致wa,这是老毛病了 还一直错#includeconst int MAXN=1000100;int father[MAXN],rank[MAXN];st... 阅读全文
posted @ 2012-08-07 08:04 calmound 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 坑爹啊。。。 这道题不难但是还是wa了四次,首先该图必须连通的**,其次房间号码大小不一定从1开始,所以他的大小可以随意的,在初始化的时候需要将持续到MAXN,当直接输入0 0的时候输出的是YES,还有就是虽然集合合并后,但是father还不一定相同,必须Find后才能相同#includeconst... 阅读全文
posted @ 2012-08-06 19:31 calmound 阅读(251) 评论(0) 推荐(0) 编辑
摘要: void Make_set(int n){ for(int i=0;irank[y]) { father[y]=x; } else { //rank[x]<rank[y],也是father[x]=y,所以省略 if(rank[x]==rank... 阅读全文
posted @ 2012-08-06 15:58 calmound 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 题意:找几个不相连的团体,最后查找发现只要father有几个是自己的,就有几个团队,这个我没想到#include#includeconst int MAXN=1010;int father[MAXN],rank[MAXN];int hash[MAXN];void Make_set(int n){ ... 阅读全文
posted @ 2012-08-06 15:57 calmound 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 01dp不过由于数组过于大,开不开,学了搜索过了,先记录下 还有一种方法#include#includeusing namespace std;const int MAXN=10000010;int a[MAXN];int n,m,ans;bool cmp(int a,int b){ retu... 阅读全文
posted @ 2012-08-05 20:49 calmound 阅读(223) 评论(1) 推荐(0) 编辑
摘要: 题意:求最大矩阵和将二维转化为一维的#include#includeint main(){ int n,i,j,k; int map[130][130],mSum[130]; while(scanf("%d",&n)!=EOF) { int max=-10000... 阅读全文
posted @ 2012-08-04 15:42 calmound 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 给定一个物品集合s={1,2,.....,n},物品i具有重量wi和价值vi。背包能承受能承受的最大载重量不超过W。背包问题就是找到一个物品子集s‘属于s,使得maxEwi1它进不了背包,背包容量为2时,进入背包,所以背包容量最大价值为12;背包容量为3,4,5时都可以进入背包,价值均为12。 ... 阅读全文
posted @ 2012-08-02 20:21 calmound 阅读(274) 评论(0) 推荐(0) 编辑
摘要: 最大子窜和,用b记录当前的和,用sum记录最大的和,当bint main(){ int a[100010]; int T,i,b,sum,n,t1,t2; int cas=1,x; scanf("%d",&T); while(T--) { scanf... 阅读全文
posted @ 2012-07-31 10:02 calmound 阅读(162) 评论(0) 推荐(0) 编辑