一、填空
侧重逻辑思维,没有语言、具体技术考察,大部分属于组合数学、算法。比较基本的知识点有二元树节点树、最小生成树、Hash函数常用方法等。
二、编程题
1、正整数剖分
2、AOE关键路径
3、二元树前序、中序求后序
4、大整数加
//正整数剖分 #include <stdio.h> int func(int n, int k, int max) { int min = (int)((n+k-1)/k); if(k==1) return 1; int count = 0; for(int i=min;i<max;i++){ count += func(n-i, k-1, max-i); } return count; } int main() { int ans; int i = 10; //ans = func(10, 3, 10); ans = func(4, 3, 4); printf("%d ", ans); return 0; }
//AOE #include <stdio.h> #include <stdlib.h> #include <string.h> void AOE(int adj[][9], int n) { int *e = (int*)malloc(sizeof(int)*n); int *l = (int*)malloc(sizeof(int)*n); e[0]=0; for(int i=1;i<n;i++){ int max = 0; for(int j=0;j<i;j++){ if(adj[j][i]!=0 && adj[j][i]+e[j]>max){ max = adj[j][i] + e[j]; } } e[i]=max; } l[n-1]=e[n-1]; for(int i=n-2;i>=0;i--){ int min = 999999; for(int j=n-1;j>i;j--){ if(adj[i][j]!=0 && l[j]-adj[i][j]<min){ min = l[j]-adj[i][j]; } } l[i]=min; } for(int i=0;i<n;i++){ if(e[i]==l[i]) printf("%d ", i+1); } printf(" "); free(e); free(l); } int main() { const int size = 9; int adj[size][size]; memset(adj, 0, sizeof(int)*size*size); adj[0][1] = 6, adj[0][2]=4, adj[0][3]=5; adj[1][4] = 1, adj[2][4]=1, adj[3][5]=2; adj[4][6] = 6, adj[4][7]=5, adj[5][7]=4; adj[6][8] = 2, adj[7][8]=4; AOE(adj, size); return 0; }
//二元树前序、中序打印后序 #include <stdio.h> #include <cstring> #include <stack> using namespace std; void dumpPost(const char* pre, const char* mid) { int n = strlen(pre); if(n==1){ printf("%c ", pre[0]); return; } int i; for(i=0;i<n;i++){ if(mid[i]==pre[0]) break; } char lpre[i], lmid[n-i-1]; char rpre[i], rmid[n-i-1]; memcpy(lpre, pre+1, sizeof(char)*i); memcpy(lmid, mid, sizeof(char)*i); memcpy(rpre, pre+i+1, sizeof(char)*(n-i-1)); memcpy(rmid, mid+i+1, sizeof(char)*(n-i-1)); lpre[i] = lmid[i] = '