时间2013-10-13;
地点复旦大学第四教学楼;
网申职位:软件开发工程师
因自己准备不是很充分,这次百度笔试考得不好,当炮灰了,继续努力准备,加油!
1、 描述OSI(开放系统互联基本参考模型)七层结构。
2、 写出进程间数据共享的方式,至少三种。
3、 描述TCP和UDP的区别,并各写出一个他们的上层协议。
程序与算法设计
1、 给出数组A={a_0,a_1,a_2,...,a_n}(n是可变的),打印出所有元素的组合
2、 数组A中任意两个相邻元素大小相差1,现给定这样的数组A和目标整数t,找出t在数组A中的位置。
3、 求二叉树的面积(高乘宽),高为二叉树根到叶子节点的最大距离,宽为二叉树最多的节点数。
#include <stdio.h>
#include <malloc.h>
//定义二叉树结点
typedef struct BiTNode {
char data;
struct BiTNode *lChild, *rChild;
} BiTNode, *BiTree;
//定义队列结点
typedef struct QNode {
BiTree data;
struct QNode *next;
} QNode, *Queue;
//定义队列
typedef struct {
Queue front;
Queue rear;
} LinkedQueue;
//创建二叉树(先序)
void createBiTree(BiTree &T) {
char c = getchar();
if(c == '*') {
T = NULL;
} else {
T = (BiTree)malloc(sizeof(BiTNode));
T->data = c;
createBiTree(T->lChild);
createBiTree(T->rChild);
}
}
//打印二叉树(中序)
void printTree(BiTree T) {
if(T) {
printTree(T->lChild);
printf("%c ", T->data);
printTree(T->rChild);
}
}
//初始化一个队列
void initQueue(LinkedQueue &Q) {
Q.front = Q.rear = (Queue)malloc(sizeof(QNode));
Q.front->next = NULL;
}
//进队
void enQueue(LinkedQueue &Q, BiTree T) {
Queue p = (Queue)malloc(sizeof(QNode));
p->data = T;
p->next = NULL;
Q.rear->next = p;
Q.rear = p;
}
//进队
void deQueue(LinkedQueue &Q, BiTree &T) {
if(Q.rear == Q.front) {
T = NULL;
return ;
}
Queue p = Q.front->next;
T = p->data;
Q.front->next = p->next;
if(p == Q.rear) Q.rear = Q.front;
free(p);
}
int max(int a, int b) {
return a>b ? a: b;
}
//求树的深度
int treeDepth(BiTree T) {
if(T) {
return max(treeDepth(T->lChild), treeDepth(T->rChild)) + 1;
} else {
return 0;
}
}
//二叉树各层结点数的最大值
int maxLayer(BiTree T) {
if(!T) return 0;
LinkedQueue Q;
initQueue(Q);
int max=0, pre = 1, h = 0, i = 0;
BiTree p = T;
enQueue(Q, p);
while(Q.front != Q.rear) {
while(i < pre) {
deQueue(Q, p);
if(p->lChild) {
h ++;
enQueue(Q, p->lChild);
}
if(p->rChild) {
h ++;
enQueue(Q, p->rChild);
}
i ++;
}
if(h > max) {
max = h;
}
pre = h;
i = 0;
h = 0;
}
return max;
}
void main() {
BiTree T;
printf("请输入二叉树结点的值:\n");
createBiTree(T);
printf("中序遍历的结果为:\n");
printTree(T);
int a, b;
a = treeDepth(T);
b = maxLayer(T);
printf("\n树的深度为:%d\n", a);
printf("树的各层结点数的最大值:%d\n", b);
printf("树的繁茂度为:%d\n", a * b);
}
系统设计题
给了一个百度地图的截图,对于地图上的某一点,需要在地图上标注该点的信息,将信息抽象成一个矩形,可以在该点的左边标记,也可以在该点右边标记。但是任意两点标记后的矩形是不能有覆盖的,否则删除其中一个点
问题1,现给一固定区域,有n个点,设计一个算法,要求标记足够多的点
问题2,当点足够多时候,算法会遇到性能瓶颈,需要对算法重新优化。