聲明:題目來自網上,此處只作知識的積累和討論,不建議轉載和傳播。node
題目:http://blog.csdn.net/wanglongfei_hust/article/details/11556337ios
筆試題:面試
1.給出一堆硬幣,不斷重複一個操做:如果正面,則隨意一拋;如果反面,則翻過來,問最後這堆硬幣的正反比例穩不穩定,穩定的話是多少?算法
答:假設最後可以穩定,則能夠獲得如下的式子:x/y=(x/2+y)/(x/2),求得x/y=2。數據庫
2.機率題。給出甲乙兩個生產車間佔全廠的比例:P(A)和P(B),再給出各自的產品不合格率:P(C|A)和P(C|B),求不合格產品是甲廠生產的機率P(A|C)?編程
答:由條件機率公式可得,P(C|A)=P(AC)/P(A),P(C|B)=P(BC)/P(B);再由全機率公式得,P(C)=P(AC)+P(BC);最後求得P(A|C)=P(AC)/P(C)=P(C|A)×P(A)/P(C)。函數
3.給出50盞燈,從1到50編號,初始全部燈處於全滅狀態;而後進行50輪按鍵,第x輪將編號爲x的倍數的燈都按一次,按一次轉換一次狀態,問最後有多少盞燈亮着?人工智能
答:對於每一個編號n,求m輪中有多少輪號是n的約數,有多少個按多少次,通常除了平方數都是約數是成對出現的,因此這道題就是在n=m的狀況下是求n之內的平方數有多少個。spa
4.有一個access()函數,如今寫一個safe_access()函數,若是調用次數>R/sec就返回錯誤,不然調用access(),返回success。.net
答:VS環境下運行正確,Linux下要從新實現clock()函數。http://bbs.csdn.net/topics/100188430
#include <time.h> #include <iostream> using namespace std; bool counter() { static clock_t last_time = 0; static double min_interval = CLOCKS_PER_SEC / 100.0; clock_t current_time = clock(); cout << current_time << endl; if( current_time - last_time < min_interval ) { cout << CLOCKS_PER_SEC << endl; cout << "interval_now: " << current_time - last_time << endl; return false; } else{ last_time = current_time; } return true; } int main() { //while( true ) { if( !counter() ) { cout << "fail" << endl; } else{ cout << "success" << endl; //system("pause"); } } return 0; }
5.交換鏈表,給一個整數k,將鏈表的每k個節點轉置,不滿k個不作操做。
答:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <malloc.h> using namespace std; struct node{ int num; node* next; }; typedef node* List; bool isHeadChange = false; node* reverseK(List pre, List end, int k) { List begin = pre->next; List kNext = end->next; List pTemp = begin; List cur = begin->next; List nTemp = cur->next; while(k--){ cur->next = pTemp; pTemp = cur; if(nTemp){ cur = nTemp; nTemp = nTemp->next; } } pre->next = cur; begin->next = kNext; return begin; } node* kReverse(List head, int k) { if(k == 1) return head; // don't know the length of list, so travel the list List tNode = head; int count = 1; // new a node to represent the pre node List pre = new node; pre->next = head; while(tNode){ // reach the 3th node if(count == 3){ // do k - 1 reverses pre = reverseK(pre, tNode, k-1); if(!isHeadChange){ head = tNode; isHeadChange = true; } tNode = pre; count = 0; } tNode = tNode->next; count++; } return head; } void print(List head) { List temp = head; while(temp != NULL){ cout << temp->num << " "; temp = temp->next; } cout << endl; } int main() { List head = new node, cur = head; head->num = 1; head->next = NULL; for(int i = 2; i <= 6; i++){ cur->next = new node; cur = cur->next; cur->num = i; cur->next = NULL; } // test print(head); head = kReverse(head, 3); print(head); return 0; }
比較兩個相同類型的指針是否相等。
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <malloc.h> using namespace std; struct node{ int num; node* next; }; int main() { node* p1 = new node; node* p2 = p1; cout << &p1 << endl; cout << &p2 << endl; cout << p1 << endl; cout << p2 << endl; cout << (*(&p1)) << endl; cout << (*(&p2)) << endl; cout << (p1==p2) << endl; cout << (&(*p1) ==&(*p2)) << endl; return 0; }
6.矩陣M[n][m],元素的每行自左向右遞增,每列的自上而下遞增,如今給一個元素elem,編程實現它的查找,而後返回位置,若是沒找到返回沒有找到的提示信息。
答:楊氏矩陣。參考博客:http://blog.csdn.net/sgbfblog/article/details/7745450
一面:
1.從新思考筆試第6道題,面試官給出一種從右上角的算法。因此筆試完也要把筆試題所有從新弄懂。
2.問項目,主要問了數據庫和系統分析課的項目。系統設計分析讓畫領域模型、EA圖等,還問那些對象之間的關係。
3.讓面試官看了下最近在寫的「坦克大戰」遊戲,討論了一下C++的問題。
二面:
1.額,第一個問題是問我畢業論文寫什麼,當時不知道說什麼,就只能說天然語言處理領域的。
2.讓寫下歸併排序,好久沒寫了,一會兒短路呢,要把排序都過一下。
3.關鍵的一題,問從5000W個int中找出top5,看過這種題,但沒去深究過,就掛掉了。
4.後面的問題就隨便問問了,問最深入的書是什麼,最喜歡哪門課,額,明顯我喜歡的都是C++。
5.對了,還讓描述了一下人工智能的項目。