随笔分类 - ALGORITHM
use c/c++ to solve the algorithm problems !
摘要:模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 1202 1205 1209 1212(大数取模) 1216(链表)1218 1219 1225 1228
阅读全文
摘要:1 #include 2 3 int main() 4 { 5 const int max = 1000001; 6 int *lpf = new int[max]; 7 int c = 2,n; 8 for(int i = 0;i < max;++i) lpf[i] = 0; 9 lpf[2] = 1;10 for(int i = 4;i < max;i += 2)11 {12 lpf[i] = lpf[2];13 }14 ...
阅读全文
摘要:花了3个多小时,这么简单地题目才AC,使用cin会超时,只能用scanf。始终想不通为什么内部循环得用__int64才能AC,用long long是WA,真郁闷,快被郁闷死了!贴上自己的代码: 1 #include 2 #include 3 #include 4 5 int main() 6 { 7 __int64 n; 8 __int64 i; 9 __int64 *sum = (__int64 *)malloc(100005*sizeof(__int64));10 memset(sum,0,sizeof(sum));11 ...
阅读全文
摘要:binaryTree.h 1 #ifndef BINARYTREE_H 2 #define BINARYTREE_H 3 4 #include 5 using namespace std; 6 7 #include 8 #include 9 #include 10 11 enum Status{ERROR,OK};//定义状态枚举时还得注意实际的值,不能搞错了 12 13 template 14 Status PrintElement(T e) 15 { 16 cout 21 class BiNode//树节点 22 { 23 public: 24 B...
阅读全文
摘要:searchBST.h 1 #ifndef SEARCHBST_H 2 #define SERACHBST_H 3 4 #include 5 #include 6 #include 7 #include 8 9 typedef int ElemType; 10 typedef enum{ERROR,OK}Status; 11 typedef int KeyType; 12 13 typedef struct BiNode 14 { 15 ElemType data; 16 struct BiNode *left,*right; 17 }BiNod...
阅读全文
摘要:prim1.h 1 #ifndef PRIM_H 2 #define PRIM_H 3 4 //* 普里姆算法,求最小生成树 5 #include 6 #include 7 #include 8 9 #define MAX_VERTEX_NUM 5 10 #define INFINITY 1000//这里不能用INT_MAX,因为如果是整型正数的最大值,加一后反而变成最小值,这点要注意 11 12 typedef int VRType; 13 typedef int VertexType; 14 typedef char InfoType; 15 typedef...
阅读全文
摘要:main.cpp 1 #include 2 #define max 10001 3 int main() 4 { 5 long s,sum,i,a[max],n,x,y,x1; 6 while(scanf("%ld",&n)>0&&n) 7 { 8 for(i=1;in)21 {22 if(a[x]==0&&a[y]==0)23 printf("0 0 0\n");24 else25 printf("0 %ld %ld\n",a...
阅读全文
摘要:fcpp.h 1 #ifndef FCCP_H 2 #define FCCP_H 3 4 #include 5 #include 6 #include 7 #include 8 9 typedef int ElemType; 10 11 ElemType position(ElemType a[],ElemType b[],int start,int end); 12 13 void swap(ElemType &a,ElemType &b) 14 { 15 ElemType temp; 16 temp = a; 17 a = b; 1...
阅读全文
摘要:huffmanTree.h 1 #include 2 #include 3 #include 4 #include 5 6 #define MAXSIZE 10 7 8 typedef struct 9 { 10 unsigned int weight; 11 unsigned int left,right,parent; 12 }HTNode,* HuffmanTree; 13 14 typedef char * * HuffmanCode; 15 16 void Select(HuffmanTree HT,int end,int &s1,i...
阅读全文
摘要:alGraph.h 1 #ifndef ALGRAPH_H 2 #define ALGRAPH_H 3 4 #include 5 #include 6 #include 7 #include 8 9 #define MAX_VERTEX_NUM 20 10 11 typedef char InfoType; 12 typedef int VertexType; 13 14 typedef enum{ERROR,OK} Status; 15 16 //---图的邻接表存储,本程序中为使用此存储方式 17 typedef struct ArcNode//弧节点 ...
阅读全文
摘要:biThrTree.h 1 #include 2 #include 3 #include 4 5 typedef int TElemType; 6 typedef enum PointerTag{Link,Thread}; 7 //线索二叉树 8 typedef struct BiThrNode 9 { 10 TElemType data; 11 struct BiThrNode *lchild,*rchild; 12 PointerTag LTag,RTag; 13 }BiThrNode, *BiThrTree; 14 15 BiThrTree ...
阅读全文
摘要:avlTree.h 1 #ifndef AVLTREE_H 2 #define AVLTREE_H 3 4 #include 5 #include 6 #include 7 #include 8 9 #define LH +1 10 #define EH 0 11 #define RH -1 12 13 typedef int ElemType; 14 typedef struct BSTNode//平衡二叉排序树结构体 15 { 16 ElemType data; 17 int bf; 18 struct BSTNode *lchild...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 #include 5 #include 6 #include 7 #include 8 9 void swap(int &a,int &b) 10 { 11 int c = a; 12 a = b; 13 b = c; 14 } 15 16 int partition(vector &vs,vector &ve,int start,int end) 17 { 18 int a = vs[start]; 19 int...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 #include 5 #include 6 #include 7 8 int main() 9 {10 double x[4],y[4];11 while(cin>>x[0]>>y[0])12 {13 for(int i = 1;i >x[i]>>y[i];16 }17 if(max(x[0],x[1]) 2 using namespace std; 3 4 #...
阅读全文
摘要:1 // HDOJ 2087 KMP算法 2 #include 3 using namespace std; 4 5 #include 6 7 void nextval(char s2[],int next[],int len) 8 { 9 next[1] = 0;10 int i = 1,j = 0;11 while(i len2) return i;37 else return 0;38 }39 40 int main()41 {42 string s1,s2;43 while(cin>...
阅读全文
摘要:1 //MILLER_RABINE素数判别法 2 #include 3 using namespace std; 4 5 #include 6 #include 7 #include 8 9 int MODULAR_EXPONENTIATION(int a,int b,int n)//a^b mod n10 {11 int c = 0,d = 1;12 vector vb;13 while(b)14 {15 vb.push_back(b%2);16 b /= 2;17 }18 int k = vb.size(...
阅读全文