上一页 1 ··· 8 9 10 11 12 13 下一页
  2013年2月2日
摘要: 基本思想1. 在图G=(V, E) (V表示顶点 ,E表示边)中,从集合V中任取一个顶点(例如取顶点v0)放入集合 U中,这时 U={v0},集合T(E)为空。2. 从v0出发寻找与U中顶点相邻(另一顶点在V中)权值最小的边的另一顶点v1,并使v1加入U。即U={v0,v1 },同时将该边加入集合T(E)中。3. 重复2,直到U=V为止。这时T(E)中有n-1条边,T = (U, T(E))就是一棵最小生成树。#include <stdio.h>#define MAXN 100#define INF (1<<20)int v[MAXN], w[MAXN][MAXN], 阅读全文
posted @ 2013-02-02 18:14 Still_Raining 阅读(298) 评论(0) 推荐(0)
  2013年2月1日
摘要: 题目连接。解题:题中的起始点为0(假设元素从0开始),终止点为n-1Dijkstra:View Code //起始为0,终点为n-1#include <stdio.h>#include <limits.h>#include <string.h>#define MAXN 102#define INF (1<<20) //如果很小的话。是不能AC的。int v[MAXN], d[MAXN], w[MAXN][MAXN];void Dijkstra(int n){ memset(v, 0, sizeof(v)); int i, y; for(i=0; 阅读全文
posted @ 2013-02-01 13:27 Still_Raining 阅读(286) 评论(0) 推荐(0)
  2013年1月28日
摘要: 题目链接。#include <stdio.h>#include <stdlib.h>#define MAXN 5000int v[MAXN], u[MAXN], p[101], w[MAXN], r[MAXN];int find(int x){return p[x] == x ? x : (p[x] = find(p[x]));}int comp(const void *a, const void *b){ int x = *(int *)a, y = *(int *)b; return w[x] - w[y];}int main(){ int n, m, i, s, 阅读全文
posted @ 2013-01-28 20:58 Still_Raining 阅读(221) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1232#include <stdio.h>#include <stdlib.h>#define MAXN 2000int v[MAXN], u[MAXN], p[MAXN];int icount;int find_f(int x){return p[x] == x ? x : (p[x]=find_f(p[x]));}int main(){ int n, m, i; while(scanf("%d", &n) == 1 && n != 0){ 阅读全文
posted @ 2013-01-28 20:09 Still_Raining 阅读(221) 评论(0) 推荐(0)
  2013年1月27日
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1233//结构体做法#include <stdio.h>#include <stdlib.h>#include <string.h>int p[101],sum,num; //p为并查集struct edge//图的结构体{ int sv,ev,w;//起始边,终边,权值。};struct edge e[10000];//必须开到大于(n*n-1)/2,否则必然RE。。。int comp(const void *a,const void *b){ return (*(str 阅读全文
posted @ 2013-01-27 20:51 Still_Raining 阅读(872) 评论(0) 推荐(0)
  2013年1月26日
摘要: #include <stdio.h>#include <string.h>#define maxn 1000//const int maxn = 1000;int lch[maxn], rch[maxn]; char op[maxn];int nc = 0;int build_tree(char *s, int x, int y){ int i, c1 = -1, c2 = -1, p = 0; int u; if(y-x == 1){ u = ++nc; lch[u] = rch[u] = 0; op[u] = s[x]; retu... 阅读全文
posted @ 2013-01-26 17:28 Still_Raining 阅读(169) 评论(0) 推荐(0)
  2013年1月16日
摘要: #include <stdio.h>#include <stdlib.h>#include <string.h>#include <conio.h>#include <limits.h>#define MAX_VERTEX_NUM 20#define MAX_VALUE_TYPE INT_MAXtypedef int VertexType;typedef struct node{ VertexType adjvex; int weight; //权值 struct node *next;}EdgeNode;typedef struct 阅读全文
posted @ 2013-01-16 19:35 Still_Raining 阅读(3324) 评论(0) 推荐(0)
摘要: 最新版的请看本博客图的三种存储方式。//邻接表 链表#include <stdio.h>#include <stdlib.h>#include <string.h>#include <conio.h>#include <limits.h>#define MAX_VERTEX_NUM 20typedef int VertexType;typedef struct node{ VertexType adjvex; int weight; //权值 struct node *next;}EdgeNode;typedef struct vno 阅读全文
posted @ 2013-01-16 14:34 Still_Raining 阅读(3386) 评论(0) 推荐(0)
  2013年1月15日
摘要: 最新版的请看本博客图的三种存储方式。#include <cstdio>#include <cstdlib>#include <cstring>#include <conio.h>#include <limits.h>#define MAXN 256#define INFINITY INT_MAX#define MAX_VERTEX_NUM 20#define OK 1typedef int VRType;typedef int InfoType;typedef int VertexType;typedef int Status;typ 阅读全文
posted @ 2013-01-15 17:00 Still_Raining 阅读(334) 评论(0) 推荐(0)
  2013年1月13日
摘要: #include <stdio.h>#include <stdlib.h>#include <string.h>#define MAXN 100int maze[MAXN][MAXN];int vis[MAXN][MAXN];int queue[MAXN*MAXN]; //队列int fa[MAXN][MAXN]; // 父结点int dx[]={0,0,-1,1};int dy[]={-1,1,0,0};int n,m; //n为行 m为列void bfs(int x, int y){ int front, rear, u, d; front = rear 阅读全文
posted @ 2013-01-13 11:51 Still_Raining 阅读(206) 评论(0) 推荐(0)
  2013年1月12日
摘要: 10106 - ProductThe ProblemThe problem is to multiply two integers X, Y. (0<=X,Y<10250)The InputThe input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.The OutputFor each input pair of lines the output line should consist one integer the product.Sample Input 阅读全文
posted @ 2013-01-12 16:46 Still_Raining 阅读(197) 评论(0) 推荐(0)
  2013年1月10日
摘要: Integer Inquiry地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=97&problem=365&mosmsg=Submission+received+with+ID+11121758One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers 阅读全文
posted @ 2013-01-10 20:47 Still_Raining 阅读(192) 评论(0) 推荐(0)
  2012年12月14日
摘要: 原地址N的阶乘中末尾有几个0 N的阶乘中末尾有几个0:如果N!= K×10M,且K不能被10整除,那么N!末尾有M个0。再考虑对N!进行质因数分解,N!=(2^x)×(3^y)×(5^z)…,由于10 = 2×5,所以M只跟X和Z相关,每一对2和5相乘可以得到一个10,于是M = min(X, Z)。不难看出X大于等于Z,因为能被2整除的数出现的频率比能被5整除的数高得多,所以把公式简化为M = Z。int count(int k) { int sum=0; while(k!=0) { k=k/5; sum+=k; ... 阅读全文
posted @ 2012-12-14 20:34 Still_Raining 阅读(618) 评论(0) 推荐(0)
  2012年12月12日
摘要: 其实玩游戏也得学程序题目地址:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2465只是用DFS练练手而已。()。//head file#include <stdio.h>#include <string.h>#include <stdlib.h>//definition#define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define OK 1#define ERROR 0#define TRUE 1# 阅读全文
posted @ 2012-12-12 18:39 Still_Raining 阅读(292) 评论(0) 推荐(0)
  2012年11月25日
摘要: LINUX 下 用GCC编译源文件时 遇到这时可以在编译时改一下就可以了。gcc -o main main.c -lm 阅读全文
posted @ 2012-11-25 11:11 Still_Raining 阅读(590) 评论(0) 推荐(0)
  2012年11月23日
摘要: #include <conio.h>#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct{ int weight; int parent, lchild,rchild;}HTNode, *HuffmanTree;typedef char ** HuffmanCode;void HuffmanCoding(HuffmanTree &HT, HuffmanCode &HC, int *w, int n); //w存放n个字符的权值,构造赫夫曼书HT 阅读全文
posted @ 2012-11-23 19:53 Still_Raining 阅读(310) 评论(0) 推荐(0)
  2012年11月10日
摘要: 走迷宫Time Limit: 1000MS Memory limit: 65536K题目描述一个由n * m 个格子组成的迷宫,起点是(1, 1), 终点是(n, m),每次可以向上下左右四个方向任意走一步,并且有些格子是不能走动,求从起点到终点经过每个格子至多一次的走法数。输入 第一行一个整数T 表示有T 组测试数据。(T <= 110)对于每组测试数据:第一行两个整数n, m,表示迷宫有n * m 个格子。(1 <= n, m <= 6, (n, m) !=(1, 1) ) 接下来n 行,每行m 个数。其中第i 行第j 个数是0 表示第i 行第j 个格子可以走,否则是1 阅读全文
posted @ 2012-11-10 20:58 Still_Raining 阅读(146) 评论(0) 推荐(0)
  2012年11月6日
摘要: 这个算法看了。很久啊。很难懂。。虽说现在会了。。不过。应用的根本不熟练老规矩。。。贴下代码。。纪念下。#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct{ char *ch; int length;}SString;int strKMP(SString *S,SString *T,int pos,int next[]); //求在主窜中S中第pos个字符之后的位置的KMP算法void get_next(SString *T,int next[]); //求模式串中T的n 阅读全文
posted @ 2012-11-06 22:19 Still_Raining 阅读(223) 评论(0) 推荐(0)
  2012年10月31日
摘要: 刚看数据结构(严蔚敏),很多东西不会。。这次。。看着伪代码。。好不容易。。写出来了。。源代码。。恩恩。。我好样的。。保留在这算是个纪念吧。。。//mainstruct.c(主函数)#include "my.h" #define N 10 int map[N][N]={ {1,1,1,1,1,1,1,1,1,1}, {1,0,0,1,0,0,0,1,0,1}, {1,0,0,1,0,0,0,1,0,1}, {1,0,0,0,0,1,1,0,0,1}, {1,0,1,1,1,0,0,0,0,1}, {1,0,0,0,1,0,0,0,0,1}, {1,0,1,0,... 阅读全文
posted @ 2012-10-31 16:21 Still_Raining 阅读(164) 评论(0) 推荐(0)
  2012年10月26日
摘要: 这是写链表时的遇到的问题。。嗯。。先写这里吧。有时间再解决。。问题地址:http://blog.csdn.net/tanheaishui/article/details/8117311这里面的。structLNodeh1,h2,h3;//h2偶数,h3奇数 如果改成structLNode *h1,*h2,*h3;//h2偶数,h3奇数然后将creat(&h1,n); 该成 creat(h1,n);执行后没有返回所建立的指针。。这里应该是和。值传递。有些关系。所建立的副本。并没有传给。h1。嗯嗯。。我还是再查查啊。(谁知道给俺说下?咋这么多高手。不来这偏僻的地方?) 阅读全文
posted @ 2012-10-26 23:43 Still_Raining 阅读(139) 评论(0) 推荐(0)
上一页 1 ··· 8 9 10 11 12 13 下一页