一家自动驾驶AI公司—纵目科技软件、算法笔试题
Settion 1: SW Program Questions
1. Implement the following macro to clear a 32 bit register’s bit 4,5 and 6
# define ClrRegBit456(x) ?
Example:
ClrRegBit456(REG_A) ;
Ans:
#define ClrRegBit456(x) ((x)&0xFFFFFFC7)
2.What is problem of the following logic and how to modify it to make it work correctly?
void allocate_mem(char *str)
{
Str = (char*) malloc(100);
}
void test()
{
char*str = NULL;
allocate_mem(str);
strcpy(str, "Hello World");
printf(str);
}
Ans:
void allocate_mem(char **str)
{
*str = (char*) malloc(100);
}
void test()
{
char*str = NULL;
allocate_mem(&str);
strcpy(str, "Hello World");
printf(str);
free(str);
}
###3. Please list the system output
unsigned char a;
unsigned short b;
unsigned int c;
unsigned long d;
unsigned long long e;
unsigned int* p1, p2;
std:: cout() << sizeof(a) << " " << sizeof(b) " " << sizeof(c) << " " << sizeof(d) << " " << sizeof(e) << " " << sizeof(p1) << " " << sizeof(p2) <<
std::end1;
Complied and run by 32bit complier
Complied and run by 64bit complier
指针位数只和编译器的位数有关。
32位机器不能实现8位整数运算,longlong 其实是扩展。
64位机器可以实现8位整数运算,所以longlong 下放到long。
complier | char | short | int | long | long long | int* p1, p2 |
---|---|---|---|---|---|---|
32 | 1 | 2 | 4 | 4 | 8 | 4, 4 |
64 | 1 | 2 | 4 | 8 | 8 | 8, 4 |
4. Please list the system output: TODO
unsigned char a = 128;
unsigned int b = ( a << 8 ) & ( a++ ) || (++a);
Ans:
#include <iostream>
using namespace std;
int main()
{
unsigned char a = 128;
unsigned int b = ( a << 8 ) & ( a++ ) || (++a);
printf("%d\n", a);
printf("%d", b);
return 0;
}
Output:
a = 130
b = 1
- [推理题 1 ]猫鼠问题. TODO
有一只猫在半径为r的圆周上以速度为v移动,猫只能在圆周上移动, 但可以自由改变方向。 圆心位置有一只老鼠。 老鼠可以在圆内自由移动, 但速度仅为 v/4。 老鼠按照什么样的策略/路线可以逃逸圆周而不被捕获。
Settion 2: SW Program Questions
The following questions just need choose any two of them.
1. implement the following 2 functions.
- Use the ANSI malloc and free functions for actual mermory allocation.
- Pointer returned by Alloc64Aligned shall be 64 byte aligned.
- Do not use global variables in your logic.
void * Alloc64Aligned (int nSize)
void Free64Aligned ( void * p )
Ans:
- Use the ANSI malloc and free functions for actual mermory allocation.
- 不能自己写内存分配函数
- Pointer returned by Alloc64Aligned shall be 64 byte aligned.
- Alloc64Aligned返回的指针必须是64字节对齐的。
- Do not use global variables in your logic.
- 不能用全局变量
void * Alloc64Aligned (int nSize){
char *ret;
int block;
int offset;
int i;
if (size<=0){
return NULL;
}
block=1+size/8;
ret=(char *)malloc(block*8);
offset=((unsigned long)ret)%8;
ret[0]=0;
for (i=1;i<8-offset;++i){
ret[i]=1;
}
return ret+8-offset;
}
void Free64Aligned ( void * p ){
char *buf;
int i;
if (p==NULL){
return ;
}
buf=(char *)p;
for (i=1;i<8;++i){
if (*(buf-i)==0){
break;
}
}
free(buf-i);
}
2. 实现一个函数,计算兔子的数量
有一对兔子,从出生后第3个月起每生一对兔子,小兔子长到第三个月后又生一对兔子,假设兔子都不死,问第n个月兔子的总数为多少?
Int CalculateRabbitCount(int monthNum)
Ans:
int CalculateRabbitCount(int monthNum){
int temp[32];
int i;
temp[0]=1;
temp[1]=1;
for (i=2;i<monthNum;++i){
temp[i]=temp[i-1]+temp[i-2];
}
return temp[monthNum-1];
}
3. 实现以下 random_sort 的函数, 对输入的数组做随机排序
rand函数是已知库函数, 可以返回0到1之间的一个浮点数
array 是输入的一个递增数组, size是数组的长度。 函数返回时的结果也存在array的数组中。
float rand(); // return random value, 0 <= random value < 1
void random_sort(int* array, int size)
Ans:
T.3
void random_sort(int* array, int size){
int i;
int p;
int e;
for (i=0;i<size-1;++i){
p=(int)(rand()*(size-i));
e=array[i];
array[i]=array[i+p];
array[i+p]=e;
}
}
4. 实现以下程序,对一帧8位灰度图实现双线性拉伸
- src_bud 是传入图像, dst_buf 是传出图像, src_width, srdc_height 是传入图像的宽高, dst_width, dst_height 是传出图像的宽高
- 双线性拉伸的定义: 当需要计算P 点的值的时候, P点的值等于分别到最临近的 A, B, C, D四个点的值乘以距离的加权平均。
void bilinear_interpotation(unsigned char* src_buf,
int src_width,
int src_height,
unsigned char* dst_buf,
int dst_width,
int dst_height)
Ans:
不会。。。
转载和疑问声明
如果你有什么疑问或者想要转载,没有允许是不能转载的哈
赞赏一下能不能转?哈哈,联系我啊,我告诉你呢 ~~
欢迎联系我哈,我会给大家慢慢解答啦~~~怎么联系我? 笨啊~ ~~ 你留言也行
你关注微信公众号1.机器学习算法工程师:2.或者扫那个二维码,后台发送 “我要找朕”,联系我也行啦!
(爱心.gif) 么么哒 ~么么哒 ~么么哒
码字不易啊啊啊,如果你觉得本文有帮助,三毛也是爱!