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

            聚精會(huì)神搞建設(shè) 一心一意謀發(fā)展
            posts - 190, comments - 17, trackbacks - 0, articles - 0
               :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            Section 3.2 - Magic Squares

            Posted on 2009-05-18 00:16 superman 閱讀(257) 評(píng)論(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 
            久久99精品国产99久久| 久久亚洲AV成人出白浆无码国产| 久久综合综合久久97色| 性做久久久久久久久| 亚洲国产婷婷香蕉久久久久久| 午夜视频久久久久一区| 国产成人久久精品麻豆一区| 午夜人妻久久久久久久久| 久久国产精品成人片免费| 久久99国产精品二区不卡| 9久久9久久精品| 久久精品国产只有精品66| 日韩人妻无码一区二区三区久久99| 久久精品久久久久观看99水蜜桃| 久久久久国产亚洲AV麻豆| 精品乱码久久久久久夜夜嗨| 青青草国产精品久久| 国产一久久香蕉国产线看观看 | 色婷婷久久综合中文久久一本| 日韩美女18网站久久精品 | 久久成人国产精品免费软件| 国产精品美女久久久久AV福利 | 97香蕉久久夜色精品国产| 国产精品亚洲美女久久久| 国产伊人久久| 99久久亚洲综合精品成人| 亚洲性久久久影院| 国产精品久久午夜夜伦鲁鲁| 人妻无码精品久久亚瑟影视| 亚洲色大成网站www久久九| 伊人久久大香线蕉AV色婷婷色| 狠狠色狠狠色综合久久| 亚洲色欲久久久综合网东京热| 久久久久亚洲AV无码麻豆| 久久婷婷人人澡人人| 久久综合视频网站| 91亚洲国产成人久久精品网址| 久久国产精品无码一区二区三区| 日本精品久久久中文字幕| 亚洲欧美精品一区久久中文字幕 | 中文国产成人精品久久不卡|