摘要: 并查集水题#include <iostream> using namespace std; const int maxn=50010; int tot,m,n; struct node { int rank; int data; int parent; }t[maxn]; void init() { for(int i=1;i<=n;i++) { t[i].data=i; t[i].rank=1; t[i].parent=i; } } int find(int p) { if(p!=t[p].parent) t[p].parent=find(t[p].parent... 阅读全文
posted @ 2012-10-15 09:12 LJ_COME!!!!! 阅读(88) 评论(0) 推荐(0)
摘要: 裸哈希,感觉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, 阅读全文
posted @ 2012-10-14 21:04 LJ_COME!!!!! 阅读(116) 评论(0) 推荐(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... 阅读全文
posted @ 2012-10-14 16:03 LJ_COME!!!!! 阅读(78) 评论(0) 推荐(0)
摘要: 树状数组,因为此是求二维数组的区间的和,所以将其扩展为二维树状数组#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 阅读全文
posted @ 2012-10-14 15:59 LJ_COME!!!!! 阅读(83) 评论(0) 推荐(0)
摘要: 欧拉回路+并查集(判断图的联通)+Tire树(快速查找字符串,并且记录相应点的度数)Tire树相关知识http://zh.wikipedia.org/wiki/Trie#include <iostream> using namespace std; const int maxc = 26; const int maxn = 500001; struct TrieNode { int key; TrieNode * child[maxc]; TrieNode() { key=-1; memset(child,0,sizeof(child)); } }; int count[ma... 阅读全文
posted @ 2012-10-12 19:47 LJ_COME!!!!! 阅读(133) 评论(0) 推荐(0)
摘要: 题不难,数据结构之BST,就是输入纠结了一会#include <iostream> #include <cstring> using namespace std; const int maxn=30; struct Tnode { char data; Tnode * lchild; Tnode * rchild; }; Tnode * root; void insert(Tnode * p,char c) { if(root==NULL) { root=new Tnode; root->data=c; root->lchild=NULL; root-> 阅读全文
posted @ 2012-10-09 23:17 LJ_COME!!!!! 阅读(105) 评论(0) 推荐(0)
摘要: 线段树,顺序存储实现#include <stdio.h> #include <string.h> const int maxx=32000; const int maxn=15000; int l[3*(maxx+1)],h[3*(maxx+1)],w[3*(maxx+1)]; int N; int ans[maxn]; void Create(int t,int s,int f) { l[t]=s;h[t]=f; if(s<f) { int mid=(s+f)/2; Create(2*t+1,s,mid); Create(2*t+2,mid+1,f); } } 阅读全文
posted @ 2012-09-29 14:22 LJ_COME!!!!! 阅读(94) 评论(0) 推荐(0)
摘要: 刚看了这道题目完全没思路,在网上找了结题报告,了解到需用离散化+线段树+扫描,但菜鸟一个,发现数据规模并不大,用离散化完全可以,所以只用了离散化,思路还是很清晰的,但还是贡献了5个小时,15次wa,纠结过后发现x,y数组我是从1开始计数的,但sort 的时候却是从0开始sort,结果导致身心煎熬了n小时,粗心惹的祸啊//离散化求解!!!!#include <iostream>#include <algorithm>using namespace std;const int maxn=210;double x[maxn],y[maxn];int vis[maxn][max 阅读全文
posted @ 2012-09-25 15:17 LJ_COME!!!!! 阅读(155) 评论(0) 推荐(0)
摘要: 第一道并查集,47ms ,还是很慢啊,不过是绞尽脑汁,调试了n次,做出来的,思路还是挺清晰地#include <iostream> using namespace std; const int maxn=30010; int parent[maxn]; int amount[maxn]; int rank[maxn]; int n,m; void init() { for(int i=0;i<n;i++) { parent[i]=i; amount[i]=1; rank[i]=0; } } int find(int t) { if(parent[t]!=t) retur... 阅读全文
posted @ 2012-09-23 20:16 LJ_COME!!!!! 阅读(97) 评论(0) 推荐(0)
摘要: 二分#include <iostream> using namespace std; const int maxn=5010; int Ui[maxn],Li[maxn],dx[maxn],dy; int amount[maxn]; int m,n,x1,y1,x2,y2; int bsearch(int xj,int yj) { int low=-1,high=m,mid; while(high-low>1) { mid=(high+low)/2; if((dy*(xj-Ui[mid])-dx[mid]*(yj-y1))<0) high=mid; else lo... 阅读全文
posted @ 2012-09-22 16:00 LJ_COME!!!!! 阅读(90) 评论(0) 推荐(0)