夏普 2021 技術崗面試題
- 管理員
- 2346閱讀
- 2021.10.11
兩個人依次拋硬幣,最先拋出正面的人獲勝,求第一個人獲勝的概率,給出分析過程
第2題:
求一個實數的指數值,a^b,補充完整下面的代碼。
??double exponention(double a, unsigned long b)
??{
??double c=1.0;
??while(b)
??{ if(b&1)c*=a;
??a=_a*a______________;
??b=_b>>1______________;
??}
??return c;
??}
第3題:
判斷兩個矩形是否相交,不相交,返回0,相交則返回相交的面積。
??struct rect
??{
??int left;
??int right;
??int top;
??int bottom
};
?
??int intersection(rect A, rect B)
??{
??}
??提示:
??求兩個矩形的最大左邊值,最大上底值,最小右邊值,最小下底值,
??即maxleft, maxtop, minright, minbottom;
??如果maxleft>minright || maxtop > minbottom,則兩個矩形相交,否則不相交
??int intersection(rect A, rect B)
??{ int maxleft, maxtop,minright, minbottom;
??maxleft=A->left > B->left?A->left:B->left;
??maxtop=A->top > B->top?A->top:B->top;
??minright=A->right right?A->right : B->right;
??minbottom=A->bottom bottom? A->bottom : B-> bottom;
??if(maxleft>minright || maxtop> minbottom)return 0;
??else return (minright -maxleft)*(minbottom-maxtop);
??}
第4題:
寫一個遞歸函數交換一顆二叉樹的左右子樹
第5題:
一個整型數組包含N個整數,其中有3個整數出現的次數均大于N/4,找出這3個數,并分析時間復雜度。