• <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>

            superman

            聚精會神搞建設 一心一意謀發展
            posts - 190, comments - 17, trackbacks - 0, articles - 0
               :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            Section 3.2 - Magic Squares

            Posted on 2009-05-18 00:16 superman 閱讀(266) 評論(0)  編輯 收藏 引用 所屬分類: USACO
             1 #include <map>
             2 #include <queue>
             3 #include <iostream>
             4 
             5 using namespace std;
             6 
             7 int init_state, target_state;
             8 
             9 void get_init_and_target_state()
            10 {
            11     init_state = 12345678;
            12     for (int i = 0, x, t = 10000000; i < 8; i++, t /= 10)
            13     {
            14         cin >> x;
            15         target_state += x * t;
            16     }
            17 }
            18 
            19 map<intstring> stateMap;
            20 
            21 int main()
            22 {
            23     freopen("msquare.in""r", stdin);
            24     freopen("msquare.out""w", stdout);
            25 
            26     get_init_and_target_state();
            27 
            28     queue<int> q;
            29     q.push(init_state);
            30     stateMap.insert(make_pair(init_state, ""));
            31 
            32     while (q.empty() == false)
            33     {
            34         int cur = q.front(); q.pop();
            35 
            36         if (cur == target_state)
            37         {
            38             cout << stateMap.find(cur)->second.size() << endl;
            39             cout << stateMap.find(cur)->second << endl;
            40             return 0;
            41         }
            42 
            43         int x[10= { 0 };
            44         for (int i = 8, t = cur; t; i--, t /= 10)
            45             x[i] = t % 10;
            46 
            47         int na = x[8* 10000000 + x[7* 1000000 + x[6* 100000 +
            48                  x[5* 10000 + x[4* 1000 + x[3* 100 + x[2* 10 + x[1];
            49 
            50         int nb = x[4* 10000000 + x[1* 1000000 + x[2* 100000 +
            51                  x[3* 10000 + x[6* 1000 + x[7* 100 + x[8* 10 + x[5];
            52 
            53         int nc = x[1* 10000000 + x[7* 1000000 + x[2* 100000 +
            54                  x[4* 10000 + x[5* 1000 + x[3* 100 + x[6* 10 + x[8];
            55 
            56         map<intstring>::iterator it;
            57         if ((it = stateMap.find(na)) == stateMap.end())
            58         {
            59             it = stateMap.find(cur);
            60             stateMap.insert(make_pair(na, it->second + 'A'));
            61             q.push(na);
            62         }
            63         if ((it = stateMap.find(nb)) == stateMap.end())
            64         {
            65             it = stateMap.find(cur);
            66             stateMap.insert(make_pair(nb, it->second + 'B'));
            67             q.push(nb);
            68         }
            69         if ((it = stateMap.find(nc)) == stateMap.end())
            70         {
            71             it = stateMap.find(cur);
            72             stateMap.insert(make_pair(nc, it->second + 'C'));
            73             q.push(nc);
            74         }
            75     }
            76 
            77     return 0;
            78 }
            79 
            久久亚洲精品国产亚洲老地址| 一本色道久久88加勒比—综合| 精品久久人人妻人人做精品| 久久久久这里只有精品| 久久婷婷色综合一区二区| 日韩精品久久久久久久电影蜜臀| 无码专区久久综合久中文字幕| 国产精品狼人久久久久影院| 日韩精品久久无码中文字幕| 激情伊人五月天久久综合| 亚洲国产成人久久笫一页| 精品久久久久久无码中文野结衣 | 久久国产亚洲精品无码| 亚洲国产成人精品久久久国产成人一区二区三区综 | 久久亚洲国产中v天仙www| 青青草原精品99久久精品66| 99久久国产主播综合精品| 久久伊人五月丁香狠狠色| 一本色综合久久| 精品久久久久久成人AV| 久久精品国产只有精品66| 久久99精品久久久久久齐齐 | 久久精品成人免费观看97| 午夜精品久久久久久99热| 久久亚洲精品国产精品婷婷| 久久―日本道色综合久久| 久久超碰97人人做人人爱| 伊人久久大香线蕉成人| 久久精品国产亚洲Aⅴ蜜臀色欲 | 久久99国产精品一区二区| 精品久久久久久无码专区不卡| 久久国产成人午夜AV影院| 69SEX久久精品国产麻豆| segui久久国产精品| 久久精品亚洲中文字幕无码麻豆| 久久久久国色AV免费看图片| 999久久久国产精品| 久久福利青草精品资源站| 99久久99这里只有免费的精品| 人妻精品久久无码区| 久久综合噜噜激激的五月天|