<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      常用算法模板

      開始存模板

       

       

      快速排序

      #include <cstdio>
      #include <algorithm>
      #include <iostream>
      
      using namespace std ; 
      typedef long long ll ; 
      const int maxN = 100010 ; 
      
      int a[ maxN ] ; 
      
      inline ll INPUT ( ) {
          ll x=0,f=1;char ch=getchar();
          while(ch<'0'||ch>'9'){if(x=='-')f=-1;ch=getchar();}
          while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
          return x*f;
      } 
      
      void quick_sort ( const int l , const int r ) {
          if ( l > r ) {
              return ; ;
          }
          int i = l , j = r ; 
          while ( i < j ) {
              while ( a[ j ] >= a[ l ] && j > i ) {
                  --j ; 
              }
              while ( a[ i ] <= a[ l ] && j > i ) {
                  ++i ; 
              }
              if ( j > i )
                  swap ( a[ i ] , a[ j ] ) ; 
          }
          swap ( a[ l ] , a[ i ] ) ;
          quick_sort ( l , i - 1 ) ;
          quick_sort ( i + 1 , r ) ; 
      }
      
      int main ( ) {
          int N = INPUT( ) ;
          for ( int i=1 ; i<=N ; ++i ) {
              a[ i ] = INPUT( ) ; 
          }
          quick_sort ( 1 , N ) ; 
          for ( int i=1 ; i<=N ; ++i ) {
              cout << a[ i ] << endl ; 
          }
          return 0 ; 
      }
      View Code

       

      快速選擇

      #include <cstdio>
      #include <algorithm>
      #include <iostream>
      
      using namespace std ; 
      typedef long long ll ; 
      const int maxN = 100010 ; 
      
      int a[ maxN ] ; 
      
      inline ll INPUT ( ) {
          ll x=0,f=1;char ch=getchar();
          while(ch<'0'||ch>'9'){if(x=='-')f=-1;ch=getchar();}
          while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
          return x*f;
      } 
      
      int quick_select ( const int l , const int r , const int K ) {
          int i = l , j = r ; 
          while ( i < j ) {
              while ( a[ j ] >= a[ l ] && j > i ) {
                  --j ; 
              }
              while ( a[ i ] <= a[ l ] && j > i ) {
                  ++i ; 
              }
              if ( j > i )
                  swap ( a[ i ] , a[ j ] ) ; 
          }
          swap ( a[ l ] , a[ i ] ) ;
          
          if ( i - l == K - 1 ) 
             return a[ i ] ;
             
          else if ( i - l >= K ) 
             return quick_select ( l , i - 1 , K ) ;
          
          else
             return quick_select( i + 1 , r , K - ( i - l + 1 ) ) ;
      }
      
      int main ( ) {
          int N = INPUT ( ) ;
          int K = INPUT ( ) ; 
          for ( int i=1 ; i<=N ; ++i ) {
              a[ i ] = INPUT( ) ; 
          }
          cout << quick_select ( 1 , N , K ) << endl ;
          return 0 ; 
      }
      View Code

       

      樹的重心

      //#include <bits/stdc++.h>
      #include <cstdio>
      #include <cstring>
      #include <algorithm>
      
      using namespace std ; 
      const int maxN = 20010 ; 
      const int inf = 2147483647 ; 
      
      struct Edge {
          int to , next ; 
      }e[ maxN << 1 ] ;
      
      int head[ maxN ] , size[ maxN ] , hv[ maxN ] ; 
      int _cnt ; 
      
      int INPUT ( ) {
          int x=0,f=1;char ch=getchar();
          while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
          while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
          return x*f;
      }
      
      void addEdge ( int x , int y ) {
          e[ ++_cnt ].to = y ; 
          e[ _cnt ].next = head[ x ] ; 
          head[ x ] = _cnt ; 
      }
      
      void Dfs ( const int x , int fa ) {
          size[ x ] = 1 ; 
          for ( int i=head[ x ] ; i ; i=e[ i ].next ) {
              if ( e[ i ].to != fa ) {
                  Dfs ( e[ i ].to , x ) ; 
                  size[ x ] += size[ e[ i ].to ] ; 
              }
          }
          for ( int i=head[ x ] ; i ; i=e[ i ].next ) {
              if ( e[ i ].to != fa && size[ e[ i ].to ] > size[ hv[ x ] ] ) {
                  hv[ x ] = e[ i ].to ;
              }
          }
      }
      void init ( ){
          _cnt = 0 ; 
          memset ( size , 0 , sizeof ( size ) ) ;
          memset ( hv , 0 , sizeof ( hv ) ) ;
          memset ( head , 0 , sizeof ( head ) ) ;
      }
      
      int main ( ) {
          for ( int T = INPUT ( ) ; T ; --T ) {
              init ( ) ; 
              int N = INPUT ( ) ;
              for ( int i=1 ; i<N ; ++i ) {
                  int x = INPUT ( ) , y = INPUT ( ); 
                  addEdge ( x , y ) ;
                  addEdge ( y , x ) ; 
              }
              Dfs ( 1 , 1 ) ; 
              int tmp , minNode = 0 , minval = inf ; 
              for ( int i=1 ; i<=N ; ++i ) {
                  int tmp = max ( size[ hv[ i ] ] , N - size[ i ] ) ;
                  if ( tmp < minval ) {
                      minval = tmp ; 
                      minNode = i ; 
                  }
              }
              printf ( "%d %d\n" , minNode , minval ) ; 
          }
          return 0 ;  
      }
      poj1655

       

      Tire樹

      #include <bits/stdc++.h>
      
      using namespace std ;
      const int maxN = 5010 ;
      typedef long long LL ; 
      
      struct tireNode {
          int cnt ; 
          bool last ; 
          struct tireNode *next[ 26 ] ; 
          tireNode ( ) {//構造方法初始化 
              cnt = 0 ; 
              last = false ; 
              memset ( next , 0 , sizeof ( next ) ) ;
          }
      }; 
      
      char str_[ maxN ] ;
      
      void insert ( tireNode *root , char str[ ] ) {
          int len = strlen ( str + 1 ) ; 
          tireNode *cur = root ;
          
          for ( int i=1 ; i<=len ; ++i ) {
              char ch = str[ i ] - 'a' ; 
              if ( cur -> next[ ch ] == NULL ) {
                  tireNode* newNode = new tireNode ; 
                  cur -> next[ ch ] = newNode ; 
              } 
              cur = cur -> next[ ch ] ;
              cur->cnt++ ; 
          }
          cur -> last = true ;
      }
      
      bool find ( tireNode *root , char str[ ] ) {
          int len = strlen ( str + 1 ) ; 
          tireNode *cur = root ; 
          for ( int i=1 ; i<=len ; ++i ) {
              char ch = str[ i ] - 'a' ; 
              if ( cur -> next[ ch ] == NULL ) return false ;
              cur = cur -> next[ ch ] ; 
          }
          if ( cur -> last == true ) return true ; 
          return false ; 
      }
      
      int main ( ) {
          int N , M ; 
          tireNode* root = new tireNode ; 
          scanf ( "%d" , &N ) ; 
          for ( int i=1 ; i<=N ; ++i ) {
              scanf ( "%s" , str_ + 1 ) ; 
              insert ( root , str_ ) ; 
          }
          scanf ( "%d" , &M ) ; 
          for ( int i=1 ; i<=M ; ++i ) {
              scanf ( "%s" , str_ + 1 ) ; 
              if ( find ( root , str_ ) ) printf ( "Yes\n" ) ;
              else printf ( "No\n" ) ;  
          }
          return 0 ; 
      }
      動態字典樹

       

      #include <bits/stdc++.h>
      
      using namespace std ;
      const int maxNode = 10010 ; 
      typedef long long LL ; 
      
      struct tireTree {
          static const int maxLen = 26 ; 
          int tr[ maxNode ][ maxLen ] ; 
          bool end[ maxNode ] ; 
          int count[ maxNode ] ; 
          int _cnt ; 
          tireTree ( ) {
              _cnt = 1 ; 
              memset ( tr , 0 , sizeof ( tr ) ) ;
              memset ( end , false , sizeof ( end ) ) ;
          }
          public :
              void insert ( char str[ ] ) {
                  int cur = 1 , len = strlen ( str + 1 ) ;
                  for ( int i=1 ; i<=len ; ++i ) {
                      int idx = str[ i ] - 'a' ; 
                      if ( !tr[ cur ][ idx ] ) {
                          tr[ cur ][ idx ] = ++_cnt ; 
                      }
                      cur = tr[ cur ][ idx ] ; 
                  }
                  end[ cur ] = true ; 
              }
              
          public :
              bool exist ( char str[ ] ) {
                  int cur = 1 , len = strlen ( str + 1 ) ;
                  for ( int i=1 ; i<=len ; ++i ) {
                      int idx = str[ i ] - 'a' ; 
                      if ( !tr[ cur ][ idx ] ) {
                          return false ; 
                      }
                      cur = tr[ cur ][ idx ] ; 
                  }
                  return end[ cur ] ; 
              }
      };
      tireTree tree ; 
      char str[ 2000 ] ;
      int main ( ) {
          int N , M ; 
          scanf ( "%d" , &N ) ; 
          for ( int i=1 ; i<=N ; ++i ) {
              scanf ( "%s" , str + 1 ) ; 
              tree.insert ( str ) ; 
          }
          scanf ( "%d" , &M ) ; 
          for ( int i=1 ; i<=M ; ++i ) {
              scanf ( "%s" , str + 1 ) ; 
              if ( tree.exist ( str ) ) 
                  printf ( "YES\n" ) ;
              else 
                  printf ( "NO\n" ) ;
          }
          return 0 ; 
      }
      靜態字典樹

       

      單調棧

      #include <iostream>
      #include <stack>
      #include <cstdio>
      
      using namespace std ; 
      const int INF = 2147483647 ; 
      
      class Element {
          private :
              int Val , Index ; 
          public :
              Element ( ) {
                  Val = 0 ;
                  Index = -1 ; 
              }
              Element ( const int __x , const int __y ) {
                  Val = __x ; 
                  Index = __y ; 
              }
              int getVal ( ) {
                  return Val ; 
              }
              int getIndex ( ) {
                  return Index ; 
              }
              void print ( ) {
                  if ( Index == -1 ) cout << "Do not exist!!" << endl ; 
                  else cout << Index << " " << Val << endl ; 
              }
      };
      
      stack <Element> stk ; 
      int arr[ 100 ] ; 
      Element Ans[ 100 ] ; 
      
      int In ( ) {
          int x = 0 , f = 1 ; char ch = getchar ( ) ;
          while ( ch < '0' || ch > '9' ) { if ( ch == '-')f = -1 ; ch = getchar ( ) ;}
          while ( ch >= '0' && ch <= '9' ) { x = ( x << 1 ) + ( x << 3 ) + ch - '0' ; ch = getchar ( ) ;}
          return x * f ;  
      }
      
      int main ( ) {
          int N = In ( ) ; 
          
          for ( int i=1 ; i<=N ; ++i ) arr[ i ] = In ( ) ; 
          
          for ( int i=1 ; i<=N+1 ; ++i ) {
              Element ele ;
              if ( i != N+1 ) ele = Element ( arr[i] , i ) ;
              else ele = Element ( INF , -1 ) ;
              while ( !stk.empty ( ) && stk.top().getVal( ) < ele.getVal() ) {
                  Ans[ stk.top().getIndex() ] = ele ;
                  stk.pop ( ) ; 
              }
              stk.push(ele) ; 
          }
          for ( int i=1 ; i<=N ; ++i ) Ans[ i ].print ( ) ; 
          return 0 ;
      } 
      View Code

       

       

       

       

      posted @ 2018-10-26 22:32  SHHHS  閱讀(889)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲av无在线播放中文| 免费午夜无码片在线观看影院| 东方av四虎在线观看| 十八禁国产一区二区三区| 麻豆国产传媒精品视频| 久久精品亚洲中文字幕无码网站 | 人妻伦理在线一二三区| 综合激情网一区二区三区| 综合亚洲网| 免费国产一区二区不卡| 人人爽人人澡人人人妻| 苍井空毛片精品久久久| 亚洲综合另类小说色区一| 国产视频一区二区在线看| 一区二区三区四区激情视频| 国产精品高清国产三级囯产AV| 亚洲人成网线在线播放VA| 99精品日本二区留学生| 国产成年码AV片在线观看| 亚洲中文字幕国产综合| 国产精品熟女一区二区三区| 人妻少妇偷人精品一区| 午夜免费福利小电影| 人妻久久久一区二区三区| 人妻体内射精一区二区三区| 免费人成视频在线观看网站 | 亚洲综合一区二区三区| 亚洲免费视频一区二区三区| 亚洲av午夜福利精品一区二区| 五月天国产成人AV免费观看| 日日躁夜夜躁狠狠久久av| 婷婷五月综合激情| 亚洲av无在线播放中文| 国产三级精品三级在线专区1| 福利一区二区视频在线| 国产日产亚洲系列av| 成人免费亚洲av在线| 国产无套精品一区二区| 一本无码在线观看| 精品亚洲香蕉久久综合网| 国产欧美精品aaaaaa片|