• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            gzwzm06

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              1 隨筆 :: 52 文章 :: 17 評論 :: 0 Trackbacks
            準確的話,需要用__i64,不用也可以過
              1 #include <cstdio>
              2 
              3 const int SIZE = 101 ;
              4 const int MAXN = 14999 ;
              5 
              6 struct HashItem
              7 {
              8     int m_num ;
              9     int m_cnt ;
             10     HashItem *next ;
             11 };
             12 
             13 HashItem hash[MAXN] , g_Temp[10001] ;
             14 int g_Pos ;
             15 int ans ;
             16 
             17 //生成x的所有可能值
             18 int gArray[SIZE] ;
             19 int P3(const int& x)
             20 {
             21     return ( x * x * x ) ;
             22 }
             23 void Produce()
             24 {
             25     for ( int i = 0 , j = 0 ; i < SIZE ; ++i )
             26     {
             27         if ( i - 50 != 0 )
             28         {
             29             gArray[j++] = P3(i - 50) ;
             30         }
             31     }
             32 }
             33 
             34 void Insert( const int& num )
             35 {
             36     int tmp ;
             37     if ( num < 0 )
             38         tmp = num * -1 ;
             39     else
             40         tmp = num ;
             41     int key = tmp % MAXN ;
             42     HashItem *ptr = &hash[key] ;
             43     
             44     while ( ptr && ptr->m_cnt != 0 )
             45     {
             46         if ( ptr->m_num == num )
             47         {
             48             ptr->m_cnt++ ;
             49             return ;
             50         } 
             51         ptr = ptr->next ;
             52     }
             53     
             54     if ( hash[key].m_cnt == 0 )
             55     {
             56         hash[key].m_num = num ;
             57         hash[key].m_cnt = 1 ;
             58     }
             59     else {
             60         ptr = &g_Temp[g_Pos++] ;
             61         ptr->m_cnt = 1 ;
             62         ptr->m_num = num ;
             63         ptr->next = hash[key].next ;
             64         hash[key].next = ptr ;
             65     }
             66     
             67 }
             68 
             69 int Find( const int& num )
             70 {
             71     int tmp ;
             72     if ( num < 0 )
             73         tmp = num * -1 ;
             74     else
             75         tmp = num ;
             76     int key = tmp % MAXN ;
             77     HashItem *ptr = &hash[key] ;
             78     
             79     if ( ptr->m_cnt == 0 )
             80     {
             81         return 0 ;
             82     }
             83     
             84     while ( ptr )
             85     {
             86         if ( ptr->m_num == num )
             87         {
             88             return ptr->m_cnt ;
             89         }
             90         
             91         ptr = ptr->next ;
             92     }
             93     
             94     return 0 ;
             95 }
             96 //計算左邊三個的值,并判斷是否滿足條件
             97 void CalLeft(const int& a, const int& b, const int& c)
             98 {
             99     int i , j , k ;
            100     int num ;
            101     for ( i = 0 ; i < SIZE - 1 ; ++i )
            102     {
            103         for ( j = 0 ; j < SIZE - 1 ; ++j )
            104         {
            105             for ( k = 0 ; k < SIZE - 1 ; ++k )
            106             {
            107                 num = gArray[i] * a + gArray[j] * b + gArray[k] * c ;
            108                 num = num * -1 ;
            109                 ans += Find(num) ;
            110             }
            111         }
            112     }
            113 }
            114 //計算右邊的值并存入hash
            115 void CalRight(const int& a, const int& b)
            116 {
            117     int i , j ;
            118     int num ;
            119     
            120     for ( i = 0 ; i < SIZE - 1 ; ++i )
            121     {
            122         for ( j = 0 ; j < SIZE - 1 ; ++j )
            123         {
            124             num = gArray[i] * a + gArray[j] * b ;
            125             Insert(num) ;
            126         }
            127     }
            128     
            129 }
            130 
            131 void Init()
            132 {
            133     for ( int i = 0 ; i < MAXN ; ++i )
            134     {
            135         hash[i].next = NULL ;
            136         hash[i].m_cnt = 0 ;
            137     }
            138     
            139     g_Pos = 0 ;
            140     ans = 0 ;
            141 }
            142 
            143 int main()
            144 {
            145    // freopen("in", "r", stdin) ;
            146     int a, b, c, d, e ;
            147     
            148     Produce() ;
            149     
            150     while ( scanf("%d%d%d%d%d", &a, &b, &c, &d, &e) != EOF )
            151     {
            152         Init() ;
            153         //轉化為 -(a + b + c) = d + e
            154         CalRight( d, e ) ; 
            155         CalLeft( a, b, c ) ; 
            156                         
            157         printf("%d\n", ans) ;
            158     }
            159     
            160     return 0 ;
            161 }
            162 



            posted on 2008-11-14 11:07 閱讀(899) 評論(0)  編輯 收藏 引用 所屬分類: Hash應用
            久久成人精品| 亚洲午夜精品久久久久久app| 久久天天躁狠狠躁夜夜avapp | 欧美午夜精品久久久久久浪潮| 久久se精品一区二区影院| 久久亚洲视频| 精品国产乱码久久久久久呢| 久久久国产精品亚洲一区| 久久久WWW成人| AV狠狠色丁香婷婷综合久久| 久久精品亚洲精品国产欧美| 欧美午夜精品久久久久免费视| 久久久国产精品| 国产韩国精品一区二区三区久久| 久久99热这里只有精品国产| 麻豆AV一区二区三区久久| 久久精品女人天堂AV麻| 久久精品欧美日韩精品| 精品久久久久久中文字幕大豆网| 国产精品99久久久久久www| 欧洲人妻丰满av无码久久不卡| 欧美激情精品久久久久久久九九九| 色综合久久无码中文字幕| 青青热久久国产久精品| 免费国产99久久久香蕉| 久久天天躁狠狠躁夜夜avapp| 欧美一区二区久久精品| 久久人人爽人人爽人人片AV东京热| 精品国产VA久久久久久久冰| 伊人久久大香线蕉亚洲五月天| 亚洲综合久久夜AV | 久久精品无码免费不卡| 国产精品激情综合久久| 久久亚洲综合色一区二区三区| 麻豆一区二区99久久久久| 久久午夜伦鲁片免费无码| 囯产极品美女高潮无套久久久 | 国产成年无码久久久久毛片 | 999久久久国产精品| 国产精品久久久久久搜索| 久久九九全国免费|