摘要:
裸哈希,感觉oj的数据弱啊,如果N很大的话,内存就不够用,可能我没想明白?#include <stdio.h>
#include <string.h>
const int maxn=16000010;
char s[maxn];
int li[300];
short hash[maxn]; int tot; int main()
{ int N,NC; scanf("%d%d",&N,&NC); scanf("%s",s); int sl=strlen(s); int t=1,i,j; memset(hash,0, 阅读全文
摘要:
此题用的是并查集的思路,时间很慢,应该有更好的思路,但以目前的知识只能做成这样#include <iostream>
using namespace std;
const int maxn=10001;
struct UFSTree
{ int data; int parent; int rank; }t[maxn];
int N;
void init()
{ int i; for(i=0;i<N;i++) { t[i].data=i; t[i].parent=i; t[i].rank=1; }
}
void Union(int p,int c)
{ t[c].p... 阅读全文
摘要:
树状数组,因为此是求二维数组的区间的和,所以将其扩展为二维树状数组#include <stdio.h>#include <memory.h>const int maxn=1100;int c[maxn][maxn];int n;int LowBit(int x){ return x&(x^(x-1));}void Update(int x,int y,int a){ for(int i=x;i<=n;i+=LowBit(i)) for(int j=y;j<=n;j+=LowBit(j)) c[i][j]+=a;}int getSum(int x,in 阅读全文