• <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應用
            久久久久婷婷| 成人国内精品久久久久影院VR| 久久九九久精品国产免费直播| 久久伊人影视| 97久久精品国产精品青草| 精品久久久久久久| 精品多毛少妇人妻AV免费久久| 国产精品禁18久久久夂久| 精品国产综合区久久久久久| 久久婷婷午色综合夜啪| 国产精品岛国久久久久| 一日本道伊人久久综合影| 91视频国产91久久久| 午夜精品久久久久久中宇| 国内精品久久久久久久久电影网| 无码国内精品久久综合88| 色综合久久最新中文字幕| 久久久久亚洲av无码专区导航| 狠狠色丁香婷婷综合久久来来去 | 国产精品免费久久| 国产成人综合久久精品红| 国产福利电影一区二区三区久久久久成人精品综合 | 国产精品久久免费| 久久99精品久久久久久动态图| 久久久久久久久波多野高潮| 久久这里只有精品视频99| 国产女人aaa级久久久级| 国产精品久久久久…| 久久久久AV综合网成人| 麻豆AV一区二区三区久久 | 97视频久久久| 一本色道久久综合狠狠躁篇| 久久久亚洲精品蜜桃臀| 久久亚洲高清综合| 久久久精品久久久久影院| 波多野结衣久久一区二区| 狠狠色丁香婷婷久久综合五月| 一级女性全黄久久生活片免费| 伊人久久大香线蕉无码麻豆| 综合久久一区二区三区| 一本色道久久HEZYO无码|