cf的邮件被腾讯当成垃圾邮件了。。。。

摘要: 我说怎么这几个星期cf都不给我发邮件了呢,原来是被腾讯拉黑了。。。。 阅读全文
posted @ 2014-02-17 13:29 Amyc 阅读(128) 评论(0) 推荐(0) 编辑

SplayTree

摘要: #include#include#includeusing namespace std;typedef int Intstruct Node{ int size,padir,reverse;};struct Stack{ int top; Stack():top(0){} Node * node[maxn]; Node * operator [](const int i)const{ return node[i]; }}stack;void Clear(Node * &root){ root=nil; root->size=0; }Node * CreatNode(){ Node 阅读全文
posted @ 2013-08-21 15:09 Amyc 阅读(247) 评论(0) 推荐(0) 编辑

LLRBTree

摘要: // RBTree#define BLACK 0#define RED 1typedef int IntStruct RBNode{ RBNode *chi[2],*pa; int color,cnt;}*nil=new RBNode(),*root=nil;void Nil(){ CreatNode(nil,0,BLACK,0); } RBNode * CreatNode(RBNode * &node,Int val,int color,int cnt=1){ if(node!=NULL && node!=nil){ RBNode *p=node; delete p; 阅读全文
posted @ 2013-08-19 11:07 Amyc 阅读(308) 评论(0) 推荐(0) 编辑

poj 2418

摘要: #include#include#include#include#include using namespace std;int cnt=0;#define abs(x) (((x)chi[0]=nil->chi[1]=nil->pa=nil; nil->bf=nil->cnt=0;}inline AVLNode * CreatNode(AVLNode * &node,Int val,int cnt=1){ if(node!=NULL && node!=nil){ AVLNode *p=node; delete p; } node=new AVL 阅读全文
posted @ 2013-08-16 22:37 Amyc 阅读(149) 评论(0) 推荐(0) 编辑

AVL

摘要: struct AVLNode{ AVLNode *kid[2],*pa; int val,cnt; int flag; AVLNode():kid[0](NULL),kid[0](NULL),pa(NULL),flag(0){}}*root,*nil;void Rotate(AVLNode *node,int drct){ AVLNode *t=node->kid[1-drct]; node->kid[1-drct]->kid[drct]->pa=node; node->kid[1-drct]=node->kid[1-drct]->kid[drct]; 阅读全文
posted @ 2013-08-14 19:42 Amyc 阅读(211) 评论(0) 推荐(0) 编辑

分拆素数和

摘要: // 分拆素数和#includeusing namespace std;bool isprime(int n){ if(n<=2) return false; int i; for(i=2;i*i<=n;i++){ if(n%i==0) return false; } //cout<<n<<" ";// return true;}int main(){ int i,n; int ans; int a[10005]={0}; for(i=3;i<=10005;i+=2){ if(isprime(i)) a[i]=1; } while( 阅读全文
posted @ 2013-08-13 21:35 Amyc 阅读(112) 评论(0) 推荐(0) 编辑

最长递增子序列

摘要: //最长递增子序列 INIT:a[]void lisub(int n){ rb[0]=0; for(int i=0,size=0;i<n;i++){ int pos=BSearchUpperBound(rb,0,size,a[i]); if(size==pos) size++; rb[pos+1]=a[i]; ans[i]=pos+1; }} 阅读全文
posted @ 2013-08-13 21:32 Amyc 阅读(92) 评论(0) 推荐(0) 编辑

深度优先搜索dfs

摘要: //深度优先搜索dfs://INIT type map[maxn][maxn]; bool vst[maxn][maxn]; //MODIFIED:const int maxn=100; void dfs(int r,int k) { int i; if(...){ //到达终点 .... //处理 return; } for(i... ){ //逐个遍历子节点 if(!vst[i] && ...){ vst[i]=1; dfs(...); //将子节点作为父节点深搜... 阅读全文
posted @ 2013-08-13 21:31 Amyc 阅读(188) 评论(0) 推荐(0) 编辑

三分查找

摘要: //三分查找(凹函数)double thirds(double low,double high){ double f1,f2; f1=fiction(low); f2=fiction(high); while(fabs(f1-f2)>eps){ double mid1 = low + (high-low)/3; double mid2 = high - (high-low)/3; f1=fiction(mid1); f2=fiction(mid2); if(f1f2) high = mid2; else if(fabs(f1-f2)<=eps) low = high; ... 阅读全文
posted @ 2013-08-13 21:30 Amyc 阅读(147) 评论(0) 推荐(0) 编辑

二分查找

摘要: //二分查找 INIT:a[]bool BinSearch(int *a,int low,int high,int target){ //a数组递增; while(lowtarget) high=mid-1; else low=mid+1; } return false;}//找到一个位置使右边的数>=此位的数 INIT:arr[]int BSearchUpperBound(int arr[], int low, int high, int target){ while(low=target) high=mid-1; if(arr[mid]<target) low... 阅读全文
posted @ 2013-08-13 21:28 Amyc 阅读(84) 评论(0) 推荐(0) 编辑