精品日本亚洲一区二区三区,99久久精品免费观看国产,99久久免费精品,亚洲精品国产一区二区成人,日本亚洲精品一区二区三区四区,国产亚洲精品成人久久网站,久久亚洲男人第一AV网站,精品国产高清一区二区广区,久久精品五月天很黄很艳女TV

考研論壇

 
查看: 1152|回復: 0
打印 上一主題 下一主題

[信息院] 2019蘭州大學計算機科學與技術復試機試試題

[復制鏈接]

1

主題

1

帖子

14

積分

新手上路

Rank: 1

精華
0
威望
2
K幣
12 元
注冊時間
2019-2-24
跳轉到指定樓層
樓主
發表于 2019-3-17 10:39 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
A. Given a sequence of  numbers, find a sub-sequence of the numbers, whose summation is the largest.  
    For example, -2 11 -4 13 -2, the largest sub-sequence in summantion is 11 -4 13. We are required to output the value of the summation and the positions the sub-sequence begins and ends. So the programe's output comes as 20 2 4    Input format:    5

    -2 11 -4 13 -2
    output format:
    20 2 4
Here is my code
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<vector>
  5. #include<map>
  6. #include<set>
  7. #include<queue>
  8. using namespace std ;

  9. const int M = 2 * 10000 + 10 ;

  10. int p[M], q[M], A[M] ;

  11. int main(){
  12.     int N ;
  13.     cin>>N ;
  14.     for( int i = 0 ; i<N; i++ ){
  15.         cin>>A[i] ;
  16.     }
  17.     p[0] = A[0] ;
  18.     q[0] = 0 ;
  19.     for( int i = 1 ; i<N ; i ++ ){
  20.         if( p[i-1] <= 0 ){
  21.             p[i] = A[i] ;
  22.             q[i] = i ;
  23.         }
  24.         else {
  25.             p[i] = p[i-1] + A[i] ;
  26.             q[i] = q[i-1] ;
  27.         }
  28.     }
  29.     int val = p[0], bg = q[0], ed = q[0] ;
  30.     for( int i = 0 ; i<N ; i++ ){
  31.         if( p[i] > val ){
  32.             val = p[i] ;
  33.             bg = q[i] ;
  34.             ed = i ;
  35.         }
  36.     }
  37.     cout<<val<<" "<< bg+ 1<<" "<<ed + 1<<endl;
  38.     return 0 ;
  39. }
  40. /* Test example
  41. 4
  42. -2 11 -4 13
  43. */
復制代碼




B: Given the frequency of every letter, use them to create a Haffman Tree and calculate the weighted path length. Output the weighted path length.
    Input format:
    8
    19 21 2 3 6 7 10 32
    output format:
    261
Here is my code
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<string>
  5. #include<vector>
  6. #include<stack>
  7. #include<map>
  8. #include<set>
  9. #include<queue>
  10. #include<cstdlib>
  11. #include<algorithm>
  12. using namespace std ;

  13. // weighted routing length of HAFFMAN Tree
  14. // 1. priority_queue to process constructing the tree
  15. //      1. each time get the top 2 node to and merge them to a new one and push it into the heap
  16. //      2. untill there is only one node left, for each new node, give a new tag and create a tree
  17. // 2. traverse the tree and tag the leaf node by the level of its position

  18. struct Node{
  19.     int val, pos ;
  20.     Node( int a , int b ): val( a ), pos( b){}
  21.     friend bool operator <( Node left, Node right){
  22.         if( left.val == right.val ) return left.pos > right.pos ;
  23.         return left.val > right.val ;
  24.     }
  25. } ;
  26. priority_queue< Node > pq ;

  27. const int M = 2 * 10000 + 10 ;
  28. vector<int> p[M] ;

  29. int q[M] ;
  30. int N , val , N1 ;

  31. int target( int father, int level ){
  32.     if( father < N )
  33.         return q[father] * level ;
  34.     return target( p[father][0], level + 1 ) + target( p[father][1] , level + 1 ) ;
  35. }

  36. int main(){
  37.     cin>> N ;
  38.     N1 = N ;
  39.     for( int i = 0 ; i < N ; i++ ){
  40.         cin>>q[i] ;
  41.         pq.push( Node(q[i], i ) ) ;
  42.     }
  43.     while( pq.size() > 1 ){
  44.         Node tmp1 = pq.top() ; pq.pop() ;
  45.         Node tmp2 = pq.top() ; pq.pop() ;
  46.         pq.push( Node( tmp1.val + tmp2.val , N1 ++ ) ) ;
  47.         p[ N1-1 ].push_back( tmp1.pos ) ;
  48.         p[ N1-1 ].push_back( tmp2.pos ) ;
  49.     }
  50.     // N1-1 is the father node
  51.     cout<< target( N1-1, 0 ) <<endl;
  52.     return 0 ;
  53. }
  54. /*
  55. Test example
  56. 8
  57. 19 21 2 3 6 7 10 32
  58. */
復制代碼

C: Given a string, find the brackets that don't match, for example, )()(, the two brackets in the middle match but the two side, which are red as ) and ( don't have a half bracket to match. We replace ')' with letter '?' and '(' with letter '$'. For the other letters in the string, we replace them by blank space.
    Input format:
    )(ab)ab)ab(
    Output format:
    )(ab)ab)ab(
    ?          ?   $Here is my
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<vector>
  4. #include<map>
  5. #include<set>
  6. #include<stack>
  7. #include<algorithm>
  8. #include<queue>
  9. using namespace std ;

  10. /*Bracket Matching
  11. traverse the string,
  12.     for letter '(' , push it directly into the stack,
  13.     for letter ')' firstly, check whether the stack is empty,
  14.         otherwise, get the top letter, if the top letter is letter '(',  pop it out,
  15.         if not, push ')' into the stack
  16. */

  17. stack<int> stck ;

  18. int main(){
  19.     string str, cpy ;
  20.     while( getline(cin, str) ){
  21.         cpy = str ;
  22.         int len = str.length() ;
  23.         for( int i = 0; i < len ; i++ ){
  24.             if( str[i] == '(')
  25.                 stck.push( i ) ;
  26.             else if( str[i] == ')'){
  27.                 if( stck.empty() )
  28.                     stck.push( i ) ;
  29.                 else{
  30.                     if( str[ stck.top() ] == '(' )
  31.                         stck.pop() ;
  32.                     else
  33.                         stck.push( i ) ;
  34.                 }
  35.             }
  36.         }
  37.         while( !stck.empty()){
  38.             if( str[stck.top() ] == ')'){
  39.                 cpy[stck.top()] = '?' ;
  40.                 stck.pop() ;
  41.             }
  42.             else{
  43.                 cpy[stck.top()] = '


  44. ;
  45.                 stck.pop() ;
  46.             }
  47.         }
  48.         for( int i = 0 ; i<len ; i++ ){
  49.             if( ( cpy[i] == '?') ||( cpy[i] == '


  50. ) ){

  51.             }
  52.             else{
  53.                 cpy[i] = ' ' ;
  54.             }
  55.         }
  56.         cout<<str<<endl;
  57.         cout<<cpy<<endl;
  58.     }
  59.     return 0 ;
  60. }
復制代碼




    回復

    使用道具 舉報

    您需要登錄后才可以回帖 登錄 | 注冊 人人連接登陸

    本版積分規則   

    關閉

    您還剩5次免費下載資料的機會哦~

    掃描二維碼下載資料

    使用手機端考研幫,進入掃一掃
    在“我”中打開掃一掃,
    掃描二維碼下載資料

    關于我們|商務合作|小黑屋|手機版|聯系我們|服務條款|隱私保護|幫學堂| 網站地圖|院校地圖|漏洞提交|考研幫

    GMT+8, 2026-5-4 04:49 , Processed in 0.077566 second(s), Total 9, Slave 8(Usage:6.75M, Links:[2]1,1_1) queries , Redis On.

    Powered by Discuz!

    © 2001-2017 考研 Inc.

    快速回復 返回頂部 返回列表
    × 關閉