上一页 1 2 3 4 5 6 7 ··· 17 下一页
摘要: 树状数组,优化查询 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!!!!! 阅读(122) 评论(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!!!!! 阅读(146) 评论(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!!!!! 阅读(157) 评论(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!!!!! 阅读(130) 评论(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!!!!! 阅读(121) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 ··· 17 下一页