05 2013 档案

摘要:AC自动机+矩阵乘法。和多数人一样。也是看了Matrix67的博客。http://www.cnblogs.com/lj030/archive/2013/05/17/3083718.html 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 #define LL long long 6 using namespace std; 7 const int maxn=11; 8 const int inf=0x3f3f3f3f; 9 co 阅读全文
posted @ 2013-05-29 20:03 LJ_COME!!!!! 阅读(174) 评论(0) 推荐(0)
摘要:LCA模板题,用的方法是转化为RMQ问题来求解,各种WA,折腾了一整天,哎~~~ 1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <cstring> 5 #include <map> 6 #include <vector> 7 using namespace std; 8 const int maxn=100000+100; 9 int pos[maxn],se[maxn*2],d[2*maxn][20];10 int e[. 阅读全文
posted @ 2013-05-28 16:37 LJ_COME!!!!! 阅读(124) 评论(0) 推荐(0)
摘要:AC自动机+DP,AC自动机还是把字符串按后缀分类,每个节点记录串的状态为本节点时会包含哪几个所给出的字符串。ans[i][j][k]表示长度为i状态为j包含的所给出的字符串为k(二进制,每一位1,0表示有没有第i个字符串)的字符串的个数。 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 #define LL long long 6 using namespace std; 7 const int mod=... 阅读全文
posted @ 2013-05-27 21:50 LJ_COME!!!!! 阅读(140) 评论(0) 推荐(0)
摘要:AC自动机的失配函数的利用和DP,Trie图中的每个节点代表一种状态,即一个字符串的后缀为从根节点到本节点的字符串。就是说把字符串根据他的后缀分为不同的类别,AC自动机上的每一个节点代表一个类别。在一个字符串的后面再加一个字符,此字符串就会从Tire图中的一个节点转移到另一个节点,这个过程可通过失配函数的求解过程中求出。其中有的节点所代表的类是不合法的,要记录下来。然后就是dp,ans[i][j]表示母串的i长度的串要变成状态为j的串所需最小修改次数。初始化为无穷大,如果j不合法不求,并且j的下一个转移得到的节点也不从j转移得到,最后比较每个节点的ans[len][j],得到最小值。 1 #. 阅读全文
posted @ 2013-05-27 13:53 LJ_COME!!!!! 阅读(166) 评论(0) 推荐(0)
摘要:三分法求下凸函数的最小值,可知,max(下凸函数,下凸函数)得到的函数认为下凸函数 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 using namespace std; 5 const int maxn=10000+10; 6 double a[maxn],b[maxn],c[maxn]; 7 int n; 8 double solve(double x) 9 {10 double maxv=a[0]*x*x+b[0]*x+c[0];11 for(int i=0;i<n; 阅读全文
posted @ 2013-05-22 21:03 LJ_COME!!!!! 阅读(165) 评论(0) 推荐(0)
摘要:贪心,没完全理解啊,明天再想想,今天已经想了一天了,唉 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 using namespace std; 5 const int maxn=1000+10; 6 int tian[maxn],qi[maxn]; 7 int main() 8 { 9 int n;10 while(scanf("%d",&n)&&n)11 {12 int i,j;13 for(i=1;i<=n;i++) 阅读全文
posted @ 2013-05-22 00:58 LJ_COME!!!!! 阅读(145) 评论(0) 推荐(0)
摘要:通过枚举每个点,也就是枚举可能的每个教练,得到在他之前的比他小的数的个数,比他大的数的个数,他之后的比他小的数的个数,比他大的数的数的个数,这个过程可通过树状数组等手段进行优化 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #define LL long long 5 using namespace std; 6 const int maxn=20000+10; 7 const int maxm=100000; 8 int n,a[maxn],sm1[maxn],sm2[ma 阅读全文
posted @ 2013-05-21 14:59 LJ_COME!!!!! 阅读(153) 评论(0) 推荐(0)
摘要:树状数组,优化查询 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int maxn=5000+10; 6 int n; 7 int a[maxn],c[maxn]; 8 int lowbit(int x) 9 {10 return x&(-x);11 }12 int query(int x)13 {14 int sum=0;15 while(x)16 {17 sum+=c[x];18 x-=... 阅读全文
posted @ 2013-05-20 19:20 LJ_COME!!!!! 阅读(127) 评论(0) 推荐(0)
摘要:模拟,标记六个方向的位置为0,1,2。。。,然后记录当前位置六种走法所要朝向的方向,而我们所需要的就是每个位置的这几个方向,很显然,其中的front所得到的方向就是当前所朝向的方向。#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct node{ int front,back,left,right,up,down;};node b_ch(node op){ node tem; tem.front=op.back; tem.back=op.front; 阅读全文
posted @ 2013-05-20 01:15 LJ_COME!!!!! 阅读(148) 评论(0) 推荐(0)
摘要:转载于Matrix67:http://www.matrix67.com/blog/archives/276 好像目前还没有这方面题目的总结。这几天连续看到四个问这类题目的人,今天在这里简单写一下。这里我们不介绍其它有关矩阵的知识,只介绍矩阵乘法和相关性质。不要以为数学中的矩阵也是黑色屏幕上不断变化的绿色字符。在数学中,一个矩阵说穿了就是一个二维数组。一个n行m列的矩阵可以乘以一个m行p列的矩阵,得到的结果是一个n行p列的矩阵,其中的第i行第j列位置上的数等于前一个矩阵第i行上的m个数与后一个矩阵第j列上的m个数对应相乘后所有m个乘积的和。比如,下面的算式表示一个2行2列的矩阵乘以2行3列的矩阵 阅读全文
posted @ 2013-05-17 15:04 LJ_COME!!!!! 阅读(347) 评论(0) 推荐(0)
摘要:求一段非递减序列出现频率最高的数字的个数,线段树做的,每个节点记录5个信息lv:区间最左边的数字,rv:区间最右边的数字ml:与区间最左边的数字相等的数字的个数,mr:与区间最右边的数字相等的数字的个数maxv:区间中出现频率最高的数字的个数,然后通过线段树查询即可以后看到与区间信息有关的题目要想到用线段树 1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 const int maxn=100000+10; 5 struct node 6 { 7 int ... 阅读全文
posted @ 2013-05-17 14:57 LJ_COME!!!!! 阅读(149) 评论(0) 推荐(0)
摘要:置换的应用。若一个置换B中所有的元素个数为偶数的循环节和它元素相等的循环节的个数为偶数个,就存在置换A使得A^2=B 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int maxn=30; 6 char s[maxn]; 7 int vis[maxn],cou[maxn]; 8 int main() 9 {10 int n;11 scanf("%d",&n);12 while(n--)13 阅读全文
posted @ 2013-05-15 19:34 LJ_COME!!!!! 阅读(159) 评论(0) 推荐(0)
摘要:AC自动机的应用,第一次做ac自动机,磕磕碰碰做了一整天,之前对于AC自动机的原理就想了好几个星期,一直没想透彻,失配函数还行,就是那个匹配过程不是很透彻,昨天又想了想,突然感觉理解了,但今天发现有些细节还是没搞透彻,唉╮(╯▽╰)╭。思路就是枚举每个方向的字符串通过利用AC自动机进行匹配,610ms水过 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 using namespace std; 6 const int maxn= 阅读全文
posted @ 2013-05-14 19:59 LJ_COME!!!!! 阅读(151) 评论(0) 推荐(0)
摘要:polya定理+欧拉函数优化,1641ms水过,具体参考的解题报告:http://www.cnblogs.com/staginner/archive/2012/03/08/2385052.html 1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 typedef long long LL; 5 int n,p; 6 int get_Eu(int x) 7 { 8 int i; 9 int ans=x;10 fo... 阅读全文
posted @ 2013-05-11 20:29 LJ_COME!!!!! 阅读(129) 评论(0) 推荐(0)
摘要:置换循环的应用。起初的状态为1,2,3......n,变换一次变为题目给出的序列,找出每个循环,可知每次变换每个字符的位置都是由本循环中的位置循环移动而来,通过模运算可得出每个字符在变换了多次之后,应该在的位置。 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int maxn=200+10; 6 char s[maxn],re[maxn]; 7 int num[maxn],vis[maxn],cir[maxn][max 阅读全文
posted @ 2013-05-07 21:12 LJ_COME!!!!! 阅读(129) 评论(0) 推荐(0)
摘要:polya定理的基础题目。置换群中有两种情况。#include <iostream> #include <cstdio> #define LL long long using namespace std; const int maxn=30; LL pow[maxn]; int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } int main() { pow[1]=3; int i; for(i=2;i<=24;i++) pow[i]=pow[i-1]*(LL)3; int n; while(scan... 阅读全文
posted @ 2013-05-05 22:11 LJ_COME!!!!! 阅读(133) 评论(0) 推荐(0)
摘要:置换的应用,但对于此题,当中关键的几部还是没理解#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int maxn=10000+10; int f1[maxn],f2[maxn],vis[100000+10],loc[100000+10]; int main() { int n; cin>>n; int i,j; for(i=0;i<n;i++) { scanf("%d",&f1[i]); l 阅读全文
posted @ 2013-05-04 15:04 LJ_COME!!!!! 阅读(124) 评论(0) 推荐(0)
摘要:多路归并+优先队列的使用#include <iostream> #include <cstdio> #include <queue> #include <algorithm> using namespace std; const int maxn=2000+10; int a[110][maxn],b[maxn],n,m; struct item { int s,b; item(int s,int b):s(s),b(b) { } }; bool operator < (item a,item b) { return a.s>b.s; 阅读全文
posted @ 2013-05-01 17:31 LJ_COME!!!!! 阅读(193) 评论(0) 推荐(0)