2012年7月9日

POJ 1936 All in All

摘要: 查找第一个串是否是第二个串的子序列;# include <stdio.h># include <string.h># define N 100005char p[N], t[N];char check(char *x, char *y){ int lenx, leny, i, j; lenx = strlen(x), leny = strlen(y); if (lenx > leny) return 0; for (i = 0, j = 0; j < leny; ++j) { if (x[i] == y[j]) ++i; if (i ... 阅读全文

posted @ 2012-07-09 16:34 getgoing 阅读(165) 评论(0) 推荐(0)

POJ 3080 Blue Jeans

摘要: 按照 CSGrandeur 的方法做的;枚举第一个串的所有子串,并查找是否在其他串中出现,需要注意题目要求在最大长度前提下,输出字典序最小的串,这里也点小难,刚开始没看懂大侠的代码,后来试了几种控制方法,有的需要先把 cstr 清空,显得麻烦,才逐渐理解了;# include <stdio.h># include <string.h># define N 65int n;char dic[15][N], cstr[N];char find(void){ char buf[N], ok; int len, i, j; cstr[0] = 0; for (len = 60; 阅读全文

posted @ 2012-07-09 16:19 getgoing 阅读(225) 评论(0) 推荐(0)

POJ 1035 Spell checker

摘要: 按照 CSGrandeur 大牛的给出的方法做的;暴力即可;判断是否可以添加一个 字符得到时,有点小技巧,具体见代码;# include <stdio.h># include <string.h># define WL 17int n;char dic[10005][WL], word[WL];char exist(char *buf){ int i; for (i = 0; i < n; ++i) { if (strcmp(dic[i], word) == 0) return 1; } return 0;}char replace(char *x,... 阅读全文

posted @ 2012-07-09 14:42 getgoing 阅读(222) 评论(0) 推荐(0)

COJ 1174 Shining Gems边界控制

摘要: 这道题对枚举时限比较严,在写 check 函数时要注意边界不能超,因为超出边界有可能引用了上一组残留的数据,而使用 memset() 则会超时。# include <stdio.h># define N 1005# define DIR 4 const int dir[][2] = {{0,1}, {1,0}, {0,-1}, {-1,0}};int n, m;char b[N][N];char check(int i, int j){ char ch; int cnt, s; for (cnt = 1, s = i-2; s<i+2; ... 阅读全文

posted @ 2012-07-09 11:33 getgoing 阅读(196) 评论(0) 推荐(0)

HDOJ 1754 I Hate It

摘要: 线段树入门题,和敌兵布阵一样只有更新和查询操作,维护的是最大值;# include <stdio.h># include <string.h># define N (1 << 19)# define M (1 << 18)int segMax[N*2+10];int max(int x, int y){ return x>y ? x:y;}void initTree(void){ segMax[0] = 0; memset(segMax, 0, sizeof(segMax));}int update(int p, int val){ p + 阅读全文

posted @ 2012-07-09 09:23 getgoing 阅读(185) 评论(0) 推荐(0)

POJ 3660 Cow Contest

摘要: 对每个结点 BFS 一遍,找出能被它打败和可以打败它的结点的总和 s ,如果 s == n-1 ,它的排名可以确定;C++ vector 邻接表;# include <cstdio># include <iostream># include <cstring># include <vector># define N 105using namespace std;int n, m;char vis[N];vector <int> pre[N];vector <int> aft[N];int bfs(int u, int d) 阅读全文

posted @ 2012-07-09 08:41 getgoing 阅读(253) 评论(0) 推荐(0)

导航