IT民工
加油!
摘要: 这道题是求图里任意两点的最短路的长度并且输出,用floyd算法可以解决这个问题,但是题目的输入比较奇葩吧,从i = 1 到 i = 19,第 i 行先输入一个数字n,代表有几个数字,后面跟着的数字都代表与 i 点直接连接的点,他们的距离为1.后面输入m,代表有多少对点,要求我们输出每队点之间的最短路径长度。#include<stdio.h>#include<string.h>#define INF 1000001int n, m, d[25][25];int x, y;int min( int a, int b){ return a < b ? a : b;}in 阅读全文
posted @ 2011-11-25 23:41 找回失去的 阅读(254) 评论(0) 推荐(1)
摘要: UVA晚上活过来了,一看到这题就感觉是并查集的题,还真是,并查集找到一个最大的集合,然后输出它的元素个数。#include<stdio.h>#include<string.h>#define MAXD 30010int p[MAXD], cnt[MAXD];int n, m;int find_set( int x){ return p[x] == x ? x : (p[x] = find_set(p[x]) );}void union_set( int x, int y){ x = find_set(x); y = find_set(y); if( x == y) re 阅读全文
posted @ 2011-11-25 21:21 找回失去的 阅读(179) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1016素数环,回溯法/*Accepted 1016 203MS 248K 1111 B C++ Yu*/#include<stdio.h>#include<string.h>int A[25], p[40], vis[25], n;void isprime(){ int i, j; for(i = 2; i < 40; i ++) p[i] = 1; p[1] = 0; for(i = 2; i * i < 40; i ++) {... 阅读全文
posted @ 2011-11-25 13:10 找回失去的 阅读(185) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2255这道题是输入二叉树的先序遍历、中序遍历,然后要求我们输出它的后序遍历,参考了白书上的二叉树重建的函数,先找到根结点,然后分别通过递归构造左右子树的后序遍历,然后将根节点放到输出字符串的最后。/*Accepted 160K 0MS C++ 563B 2012-07-31 12:16:15*/#include<stdio.h>#include<string.h>const int MAXN = 1 << 5;char s1[MAXN], s2[MAXN], ans[MAXN];void build(in 阅读全文
posted @ 2011-11-25 12:13 找回失去的 阅读(182) 评论(0) 推荐(1)