• <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 
            伊人久久大香线蕉综合热线| 精品视频久久久久| 亚洲精品成人网久久久久久| 中文成人久久久久影院免费观看| 国产精品美女久久福利网站| www久久久天天com| 久久人人爽人人爽人人片AV东京热| 国产精品久久新婚兰兰| 久久不射电影网| 欧美黑人激情性久久| 久久青青草原精品国产不卡| 久久99国产综合精品免费| 亚洲国产成人久久综合野外| 久久综合丁香激情久久| 久久久久高潮毛片免费全部播放| 国内精品伊人久久久影院| 久久久精品免费国产四虎| 东方aⅴ免费观看久久av| 久久亚洲精品成人无码网站| 久久精品国产亚洲av瑜伽| 99久久精品无码一区二区毛片 | 国内精品伊人久久久久妇| 精品久久久久久亚洲| 99久久99久久久精品齐齐| 久久久久亚洲av无码专区导航 | 7国产欧美日韩综合天堂中文久久久久| 人妻中文久久久久| 日日狠狠久久偷偷色综合96蜜桃 | 成人综合伊人五月婷久久| 亚洲va久久久噜噜噜久久| 亚洲精品无码专区久久久| 综合久久一区二区三区 | 国产精品99久久久久久猫咪 | 国产亚洲精久久久久久无码AV| 97久久香蕉国产线看观看| 久久99久久99精品免视看动漫| 久久久久久久久无码精品亚洲日韩 | 精品久久久久久久久午夜福利| 亚洲香蕉网久久综合影视| 精品久久久无码人妻中文字幕| 人妻久久久一区二区三区|