2012年8月14日

hdoj 1242

摘要: 1 #include <iostream> 2 #include <queue> 3 #define inf 0x7ffffff 4 using namespace std; 5 char map[203][203]; 6 int visit[203][203]; 7 int n, m, di, dj; 8 int dir[4][2] = {{1, 0},{-1, 0},{0, 1},{0, -1}}; 9 struct node10 {11 int i, j;12 int cnt;13 int f;14 };15 bool check(node s)16 {17 .. 阅读全文

posted @ 2012-08-14 22:02 Xor<>OR 阅读(178) 评论(0) 推荐(0)

2012年8月11日

hdoj 1010 Tempter of the Bone

摘要: 1 #include <stdio.h> 2 #include <iostream> 3 #include <math.h> 4 5 using namespace std; 6 7 int n, m, t, di, dj, success; 8 char maze[10][10]; 9 10 void dfs(int i, int j, int cnt)11 {12 int temp;13 if (i == di && j == dj && cnt == t)14 {15 success = 1;16 return;17 . 阅读全文

posted @ 2012-08-11 18:25 Xor<>OR 阅读(124) 评论(0) 推荐(0)

hdoj 2066 一个人的旅行

摘要: 最短路问题,把0(小草所在的)城市与相邻城市设置为0,然后就是求出每想去城市的最短路径,从每个最短路径中取出最小值 1 #include <stdio.h> 2 #define min(a, b) a < b ? a : b 3 #define inf 0x7FFFFFFF 4 #define M 1001 5 6 int map[M][M]; 7 int dist[M]; 8 int visit[M]; 9 10 int t, s, d, k;11 12 int mdist(int res, int des) //最短路函数13 {14 int i = 0;15 for ( 阅读全文

posted @ 2012-08-11 12:43 Xor<>OR 阅读(230) 评论(0) 推荐(0)

2012年8月10日

回文字符串

摘要: 经典动归算法,优化了下空间 1 #include <stdio.h> 2 #include <string.h> 3 4 int a[2][1002]; 5 char b[1002]; 6 char c[1002]; 7 8 int main() 9 {10 int n;11 scanf("%d", &n);12 while (n--)13 {14 memset(a, 0, sizeof(a));15 memset(c, 0, sizeof(c));16 scanf("%s", b);17 in... 阅读全文

posted @ 2012-08-10 10:57 Xor<>OR 阅读(146) 评论(0) 推荐(0)

2012年8月9日

hdoj 1232 畅通工程

摘要: 裸的并查集,把每个集合看成一个点,然后点的总和减1就是道路条数,比如两个点之间连通最少需要1条路; 1 #include <stdio.h> 2 3 int set[1001]; 4 5 int find(int n)//寻找祖先,类似双亲树 6 { 7 while (set[n] != n)//o(logN) 8 n = set[n]; 9 return n;10 }11 12 void merge(int a, int b)//合并集合13 {14 b = find(b);15 set[b] = a;//用a的值覆盖b祖先的值,a的祖先就... 阅读全文

posted @ 2012-08-09 19:30 Xor<>OR 阅读(125) 评论(0) 推荐(0)

括号匹配(栈做法)

摘要: 1 #include <stdio.h> 2 #include <string.h> 3 4 char s[10002]; //栈 5 6 int main() 7 { 8 int n; 9 scanf("%d", &n);10 getchar();11 memset(s, 0, sizeof(s));12 while (n--)13 {14 int top = 0;//栈标始终指向栈顶元素15 char c;16 while ((c = getchar()) != '\n' )17 {18 if ((c == ')& 阅读全文

posted @ 2012-08-09 14:03 Xor<>OR 阅读(160) 评论(0) 推荐(0)

hdoj 2602 (01背包问题)

摘要: 裸的背包 1 #include <stdio.h> 2 #include <string.h> 3 4 struct t 5 { 6 int w; 7 int v; 8 }; 9 10 int r[1002];11 t a[1002];12 13 int main()14 {15 int n;16 scanf("%d", &n);17 while (n--)18 {19 memset(r, 0, sizeof(r)); //数组清零不能忘记!20 int N, V, i, j;21 scanf("... 阅读全文

posted @ 2012-08-09 10:10 Xor<>OR 阅读(146) 评论(0) 推荐(0)

嵌套矩形

摘要: 其实就是最大子序列的变形,首先排序; 1 #include <stdio.h> 2 #include <algorithm> 3 4 using namespace std; 5 6 struct re 7 { 8 int a;//长 9 int b;//宽10 int c;//计数器11 };12 13 re r[1001];14 15 bool cmp(re t1, re t2)16 {17 return t1.a < t2.a;18 }19 20 int main()21 {22 int n;23 scanf("%d", &n); 阅读全文

posted @ 2012-08-09 09:45 Xor<>OR 阅读(308) 评论(0) 推荐(0)

导航