上一页 1 ··· 50 51 52 53 54 55 56 57 58 ··· 182 下一页
摘要: 简单题View Code #include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>using namespace std;int main(){ int n; scanf("%d", &n); if (n >= 199) printf("0\n"); else printf("%d\n", 199 - n); return 0;} 阅读全文
posted @ 2012-10-19 22:18 undefined2024 阅读(127) 评论(0) 推荐(0)
摘要: dfa,ac自动机。题意:给定一些单词,给定一个矩阵,在矩阵内8方向找每个单词是否出现过。输出每个单词的出现位置和方向。分析:分别以位于矩阵四周的点作为起点,每个起点找向8个方向最长的字符串,分别加入自动机。View Code #include #include #include #include using namespace std;const int kind = 26;struct node{ node *fail; //失败指针 node *next[kind]; //Tire每个节点的26个子节点(最多26个字母) int id; //是否为该单词的最后一个节点 ... 阅读全文
posted @ 2012-07-11 18:12 undefined2024 阅读(1143) 评论(0) 推荐(0)
摘要: 完全背包View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;#define maxm 50005#define maxn 15int n, m, y;int weight[maxn], value[maxn];int f[maxm];void input(){ scanf("%d%d", &m, &y); scanf( 阅读全文
posted @ 2012-07-10 19:25 undefined2024 阅读(228) 评论(0) 推荐(0)
摘要: 题意:有m层楼,从一层到m层,要进入每层都要打开位于该层的两道门中的至少一道。门锁有2n种,每个门锁为2n种中的一种,可以重复。有2n把钥匙,分别对应2n种锁,但是钥匙两两一组,共n组,每组只能选一个来开门,被选中的可以多次使用,另一个一次都不能用。问最多能上多少层。分析:二分查找能上的层数。每次对于一个确定的层数,也就确定了哪些门需要开。变为一个2-sat问题。其中两两一组的钥匙就是图中的节点。当然图中还需要一些矛盾。矛盾如下,某层有x,y两种锁,x的钥匙a与钥匙b一组,y的要是c与钥匙d一组。如果在某次选了钥匙b,那么本层的x将无法被打开,只能开y,就必须选钥匙c,不能选钥匙d。所以钥匙b 阅读全文
posted @ 2012-07-10 16:32 undefined2024 阅读(934) 评论(0) 推荐(1)
摘要: 题意:给出n个互不相同的数字,要求一个最大的子段,使得该子段内所有数(除了两端以外),值都在两端的数字之间,且不能等于两端的数。分析:先对整个数组分别构造最大值RMQ和最小值RMQ的st数组。然后,枚举子段起点,对于每个起点求出这个起点是区间最小值的最远终点(用二分查找)。然后在这个区间内找到最大值位置,从起点到最大值位置这个区间就是起点所对应的符合题意的最大区间。枚举过所有的起点之后,结果就求出来了。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cs 阅读全文
posted @ 2012-07-10 14:11 undefined2024 阅读(661) 评论(0) 推荐(0)
上一页 1 ··· 50 51 52 53 54 55 56 57 58 ··· 182 下一页