锘??xml version="1.0" encoding="utf-8" standalone="yes"?>四虎国产精品成人免费久久,国产午夜免费高清久久影院,久久久国产精品网站http://www.shnenglu.com/luxiuyuan/archive/2012/04/22/172359.html璺慨榪?/dc:creator>璺慨榪?/author>Sun, 22 Apr 2012 12:23:00 GMThttp://www.shnenglu.com/luxiuyuan/archive/2012/04/22/172359.htmlhttp://www.shnenglu.com/luxiuyuan/comments/172359.htmlhttp://www.shnenglu.com/luxiuyuan/archive/2012/04/22/172359.html#Feedback0http://www.shnenglu.com/luxiuyuan/comments/commentRss/172359.htmlhttp://www.shnenglu.com/luxiuyuan/services/trackbacks/172359.html      bfs鐨勫ソ棰樼洰錛?br />      寮濮嬫兂鍒扮敤浼樺厛闃熷垪錛屾棤鎯呯殑榪樻槸榪囦簡錛?鍙笉榪囨椂闂寸敤浜?000ms澶氾紝宸偣灝辨寕浜唦鏉叿鐨勪紭鍏?br />      鍚庢潵涓鎯籌紝鍏跺疄鍙互鐩存帴bfs, 鏈夋儏鐨勬槸鎰忔枡涔嬪鐨勬病鏈夊嚭鐜癟E錛岃屾槸AC錛屽交搴曟棤璇殑鏄彧鐢ㄤ簡500ms澶氾紒錛侊紒錛?br />      澶у懠浼樺厛涔嬪搥鍝?#8230;…
      鑷充簬bfs鐨勫仛娉曞涓嬶細
            1錛屽紑濮嬬偣榪涙爤
            2錛屽紑濮嬬偣鑳界洿鎺ュ埌杈?涓嶈姳鏃墮棿鐨?鐨勬墍鏈夌殑鐐硅繘鏍?br />            3錛屽垎涓ゆ
               3.1 寮濮嬬偣涓嶈兘鐩存帴鍒拌揪錛堣鏃墮棿錛夌殑鐐硅繘鏍?br />               3.2 灝嗚繖涓偣鑳界洿鎺ュ埌杈?涓嶈姳鏃墮棿鐨?鐨勬墍鏈夌殑鐐硅繘鏍?br />               3.3 璺寵漿鍒?
           4 璺寵漿鍒?
         娉細寮濮嬬偣涓哄綋鍓嶅嚭鏍堢殑絎竴涓偣
        涓嶆槑鐧借繖涓繃紼嬬殑鍙互鐪嬩唬鐮侊紙铏界劧浠g爜鏈夌偣……錛岃繕鍙互榪涗竴姝ョ畝鍖栵紝 浠ュ悗涓嶈兘鑰佹兂鐫浼樺厛浜嗭紝璋佷紭鍏堣皝鏉叿錛屽綋鐒朵笉鏄鎴戜滑鐨勫箍澶уコ鍚岃優……錛?br />
  1 #include <iostream>
  2 #include <queue>
  3 using namespace std;
  4 struct node
  5 {
  6        int x, y, time;
  7        /*friend bool operator < (node a, node b)
  8        {
  9               return a.time > b.time;
 10        }*/
 11 };
 12 int n, m;
 13 int xi[8= {-1-101110-1};
 14 int yi[8= {01110-1-1-1};
 15 char map[1005][1005];
 16 bool vist[1005][1005];
 17 bool check(int dx, int dy)
 18 {
 19      if (dx >= 0 && dy >=0 && dx < n && dy < m) return true;
 20      return false;
 21 }
 22 queue <node> q;
 23 int bfs(node now, node end)
 24 {
 25     while (!q.empty())q.pop();
 26     now.time = 0;
 27     q.push(now);
 28     
 29     for (int i = 0; i < n; i++)
 30     for (int j = 0; j < m; j++)
 31         vist[i][j] = false;
 32     vist[now.x][now.y] = true;
 33     node next, tmp;
 34     bool flag = false;
 35     while (!q.empty())
 36     {
 37           now = q.front();
 38           tmp = now;
 39           if (now.x == end.x && now.y == end.y) return now.time;
 40           q.pop();
 41           flag = false;
 42           while (1)
 43           {
 44                 next.x = tmp.x + xi[map[tmp.x][tmp.y]-'0'];
 45                 next.y = tmp.y + yi[map[tmp.x][tmp.y]-'0'];
 46                 if (check(next.x, next.y) && !vist[next.x][next.y])
 47                 {
 48                    if (next.x == end.x && next.y == end.y) return tmp.time;
 49                    next.time = tmp.time;
 50                    vist[next.x][next.y] = true;
 51                    q.push(next);
 52                    tmp = next;
 53                 }else break;
 54           }
 55           for (int i = 0; i < 8; i++)
 56           {
 57               next.x = now.x + xi[i];
 58               next.y = now.y + yi[i];
 59               if (check(next.x, next.y) && !vist[next.x][next.y])
 60               {
 61                  if (map[now.x][now.y] - '0' == i) next.time = now.time;
 62                  else next.time = now.time + 1;
 63                  if (next.x == end.x && next.y == end.y) return next.time;
 64                  vist[next.x][next.y] = true;
 65                  q.push(next);
 66                  tmp = next;
 67                  while (1)
 68                  {
 69                        next.x = tmp.x + xi[map[tmp.x][tmp.y]-'0'];
 70                        next.y = tmp.y + yi[map[tmp.x][tmp.y]-'0'];
 71                        if (check(next.x, next.y) && !vist[next.x][next.y])
 72                        {
 73                           if (next.x == end.x && next.y == end.y) return tmp.time;
 74                           next.time = tmp.time;
 75                           vist[next.x][next.y] = true;
 76                           q.push(next);
 77                           tmp = next;
 78                        }else break;
 79                   }
 80               }
 81           }
 82     }
 83     return 0;
 84 }
 85 int main()
 86 {
 87     while (scanf("%d%d"&n, &m) != EOF)
 88     {
 89           int i, j;
 90           for (i = 0; i < n; i++)
 91               scanf("%s", map[i]);
 92           int T;
 93           scanf("%d"&T);
 94           node now, end;
 95           for (i = 0; i < T; i++)
 96           {
 97               scanf("%d%d%d%d"&now.x, &now.y, &end.x, &end.y);
 98               now.time = 0;
 99               now.x --;
100               now.y --;
101               end.x --;
102               end.y --;
103               if (now.x == end.x && now.y == end.y)
104               {
105                  printf("0\n");
106               }else printf("%d\n", bfs(now, end));
107           }
108     }
109 return 0;
110 }
111 



]]>
Hdoj 2364 Escapehttp://www.shnenglu.com/luxiuyuan/archive/2012/04/13/171268.html璺慨榪?/dc:creator>璺慨榪?/author>Fri, 13 Apr 2012 10:34:00 GMThttp://www.shnenglu.com/luxiuyuan/archive/2012/04/13/171268.htmlhttp://www.shnenglu.com/luxiuyuan/comments/171268.htmlhttp://www.shnenglu.com/luxiuyuan/archive/2012/04/13/171268.html#Feedback0http://www.shnenglu.com/luxiuyuan/comments/commentRss/171268.htmlhttp://www.shnenglu.com/luxiuyuan/services/trackbacks/171268.html      鏈濂藉紑涓涓笁緇寸殑鏁扮粍錛岃褰曟瘡涓涓牸瀛愮殑姣忎竴涓柟鍚戜笂鐨勬渶灝忓鹼紝鐩村埌bfs瀹屾垚
      鍏蜂綋鐪嬩唬鐮侊紝涓嶅仛榪囧鐨勮В閲娿?
  1 #include <iostream>
  2 #include <queue>
  3 using namespace std;
  4 struct node
  5 {
  6        int x, y;
  7        int step, dir;
  8 };
  9 int n, m;
 10 int xi[4= {01-10};
 11 int yi[4= {100-1};
 12 int vist[82][82][4];
 13 char map[82][82];
 14 node start;
 15 queue <node> q;
 16 bool check(int dx, int dy)
 17 {
 18      if(dx >= 1 && dx <= n && dy >= 1 && dy <= m) return true;
 19      else return false;
 20 }
 21 bool find(node a)
 22 {
 23      if ((a.x == 1 || a.x == n || a.y == 1 || a.y == m)) return true;
 24      else return false;
 25 }
 26 int bfs()
 27 {
 28      while (!q.empty())q.pop();
 29      memset(vist, 0sizeof(vist));
 30      start.dir = -1;
 31      start.step = 0;
 32      q.push(start);
 33      node now, next;
 34      bool flag = true;
 35      int tmp;
 36      while (!q.empty())
 37      {
 38            now = q.front();
 39            q.pop();
 40            if (find(now)) return now.step;
 41            
 42            flag = false;
 43            for (int i = 0 ; i < 4; i++)
 44            {
 45               if (now.dir == i) continue;
 46               if (now.dir >=0 && 3-now.dir == i) continue;
 47               next.x = now.x + xi[i];
 48               next.y = now.y + yi[i];
 49               next.step = now.step + 1;
 50               if (check(next.x, next.y) && map[next.x][next.y] == '.' )
 51               {
 52                  if (vist[next.x][next.y][i] == 0)  
 53                  {
 54                     vist[next.x][next.y][i] = next.step;
 55                     next.dir = i;
 56                     q.push(next);
 57                  }
 58                  else if (vist[next.x][next.y][i] > next.step)
 59                  {
 60                     vist[next.x][next.y][i] = next.step;
 61                     next.dir = i;
 62                     q.push(next);
 63                  }
 64                  flag = true;
 65               }
 66            }
 67            if (!flag)
 68            {
 69               int i = now.dir;
 70               if (i < 0return 0;
 71               next.x = now.x + xi[i];
 72               next.y = now.y + yi[i];
 73               next.step = now.step + 1;
 74               if (check(next.x, next.y) && map[next.x][next.y] == '.' )
 75               {
 76                  if (vist[next.x][next.y][i] == 0)  
 77                  {
 78                     vist[next.x][next.y][i] = next.step;
 79                     next.dir = i;
 80                     q.push(next);
 81                  }
 82                  else if (vist[next.x][next.y][i] > next.step)
 83                  {
 84                     vist[next.x][next.y][i] = next.step;
 85                     next.dir = i;
 86                     q.push(next);
 87                  }
 88                  flag = true;
 89               }
 90            }
 91      }
 92      return -1;
 93 }
 94 int main()
 95 {
 96     int cas;
 97     scanf("%d"&cas);
 98     while (cas--)
 99     {
100           scanf("%d%d"&n, &m);
101           int i, j;
102           for (i = 1; i <= n; i++)
103               scanf("%s", map[i]+1);
104           for (i = 1; i <= n; i++)
105           for (j = 1; j <= m; j++)
106           {
107               if (map[i][j] == '@')
108               {
109                  start.x = i;
110                  start.y = j;
111                  map[i][j] = '.';
112               }
113           }
114           int ans = bfs();
115           printf("%d\n", ans);
116     }
117 return 0;
118 }
119 


]]>
HDU 2433 鏈鐭礬http://www.shnenglu.com/luxiuyuan/archive/2012/03/09/167494.html璺慨榪?/dc:creator>璺慨榪?/author>Fri, 09 Mar 2012 07:35:00 GMThttp://www.shnenglu.com/luxiuyuan/archive/2012/03/09/167494.htmlhttp://www.shnenglu.com/luxiuyuan/comments/167494.htmlhttp://www.shnenglu.com/luxiuyuan/archive/2012/03/09/167494.html#Feedback0http://www.shnenglu.com/luxiuyuan/comments/commentRss/167494.htmlhttp://www.shnenglu.com/luxiuyuan/services/trackbacks/167494.html   鍘繪帀緇欏畾鐨勮竟錛岀湅姣忎竴涓偣鏄惁鑳戒粠鍒殑鐐瑰埌杈撅紒
    濡傛灉鑳藉鍒拌揪錛屽垯姹傚嚭瀵逛簬姣忎竴涓偣鍒板叾浠栨墍鏈夌殑鐐規渶鐭窛紱諱箣鍜岋紝灝嗚繖浜涘拰鐩稿姞灝辨槸鏈鍚庣殑緇撴灉

   瑙i鎬濊礬錛?br />      瀵規瘡涓涓偣姹備竴嬈″崟婧愭渶鐭礬錛岀劧鍚庢眰鍜岋紝鐩稿姞鐨勫埌鏈鍚庣殑緇撴灉……
      浣嗭紝綆椾竴涓嬫椂闂村鏉傚害錛?澶嶆潅搴︽槸O(M*N*M)銆傜敱浜嶮*N*M=3000*100*3000=9*108錛屼笉鍙兘AC

      鎵浠ワ紝闇瑕佹垜浠彟杈熶粬寰勩傜綉涓婃湁璇村緩浠涔堟渶鐭礬寰勬爲錛岃繖涓垜涓嶆噦……
      鎴戠殑鎬濊礬鏄細寮曠敤鍓嶉潰鐨勬濊礬錛屽姣忎竴涓偣姹備竴嬈℃渶鐭礬錛屽茍灝嗗叾姹傚拰錛屼繚瀛樺湪涓涓暟緇勯噷澶達紝瀹氫負sum[i]錛宨琛ㄧず鐫涓涓偣鍒版墍鏈夊叾浠栫偣鏈鐭礬涔嬪拰銆傚茍灝嗚繖浜涘拰鐩稿姞 ans = sum[1]  + …… + sum[n]; 
      鐒跺悗錛屽垹闄や竴鏉¤竟錛屽叾欏剁偣鏆傚畾涓簎,v錛屽榪欐潯杈圭殑涓涓《鐐箄鍦ㄤ竴嬈℃眰鏈鐭礬錛屽鏋滆繖涓偣錛屼笉鑳藉埌杈捐繖鏉¤竟鐨勫彟涓涓偣v錛屽垯 鐩存帴杈撳嚭INF
      濡傛灉錛岃兘澶熷埌杈撅紝鍒欏v涔熸眰涓嬈℃渶鐭礬錛屽浜巙錛寁涓ょ偣鏉ヨ錛屾眰寰梪鍒版瘡涓涓偣鐨勬渶鐭礬涔嬪拰sum_u錛屾眰寰梫鍒版瘡涓涓偣鐨勬渶鐭礬涔嬪拰sum_v錛?br />      鏈鍚庣粨鏋滀負錛?ans = ans + sum_u + sum_v - sum[u] - sum[v];
      ans涓烘渶鍚庣瓟妗堬紙鍗冧竾璁頒綇鏄瘡涓緇勭殑錛屽洜涓烘湁m鏉¤竟錛?br />      鍏蜂綋鐪嬩唬鐮侊細
http://acm.hdu.edu.cn/showproblem.php?pid=2433
鏃墮棿鏄?953ms
         
  1 #include <iostream>
  2 #include <queue>
  3 using namespace std;
  4 const int SIZE = 102;
  5 const int INF = 1 << 30;
  6 struct node
  7 {
  8        int v, w, next;
  9 }map[SIZE * SIZE];
 10 
 11 int head[SIZE], use;
 12 int num[SIZE * 30];
 13 int sum[SIZE];
 14 
 15 void add(int u, int v, int w)
 16 {
 17      map[use].v = v;
 18      map[use].w = w;
 19      map[use].next = head[u];
 20      head[u] = use ++;
 21 }
 22 void init()
 23 {
 24      use = 0;
 25      memset(head, -1sizeof(head));
 26      memset(sum, 0sizeof(sum));
 27 }
 28 
 29 queue <int> q;
 30 bool vist[SIZE];
 31 int dis[SIZE];
 32 
 33 int spfa(int s)
 34 {
 35      while (!q.empty()) q.pop();
 36      
 37      for (int i = 0; i < SIZE ; i ++)  dis[i] = INF;
 38      
 39      memset(vist, falsesizeof(vist));
 40      dis[s] = 0;
 41      vist[s] = true;
 42      q.push(s);
 43      int ans = 0;
 44      while (!q.empty()) 
 45      {
 46            int u = q.front();
 47            q.pop();
 48            vist[u] = false;
 49            ans += dis[u];
 50            for (int i = head[u]; i != -1; i = map[i].next)
 51            {
 52                int v = map[i].v;
 53                if (dis[v] > dis[u] + map[i].w)
 54                {
 55                   dis[v] = dis[u] + map[i].w;
 56                   if (!vist[v])
 57                   {
 58                      vist[v] = true;
 59                      q.push(v);
 60                   }
 61                }
 62            }
 63      }
 64      return ans;
 65 }
 66 int main()
 67 {
 68      int n, m;
 69      while (scanf("%d%d"&n, &m) != EOF)
 70      {
 71            int i, j, k;
 72            int u, v;
 73            init();
 74            memset(num, 0sizeof(num));
 75            for (i = 1; i <= m; i++)
 76            {
 77                scanf("%d%d"&u, &v);
 78                num[i] = use;
 79                add(u, v, 1);
 80                add(v, u, 1);
 81            }
 82            int ans = 0;
 83            for (i = 1; i <= n; i++)  
 84            {
 85                sum[i] = spfa(i);
 86                ans += sum[i];
 87            }
 88            int tmp = ans;
 89            for (i = 1; i <= m; i++)
 90            {
 91                map[num[i]].w = INF;
 92                map[num[i]^1].w = INF;
 93                
 94                ans = tmp;
 95                ans += spfa(map[num[i]].v);
 96                
 97                if (dis[map[num[i]^1].v] == INF) 
 98                {
 99                   printf("INF\n");
100                }
101                else 
102                {
103                     ans += spfa(map[num[i]^1].v);
104                     ans = ans - sum[map[num[i]].v] - sum[map[num[i]^1].v];
105                     printf("%d\n", ans);
106                }
107                map[num[i]].w = 1;
108                map[num[i]^1].w = 1;
109            }
110      }
111 return 0;
112 }
113 

   

]]>
絎竷灞婃箹鍗楃渷澶у鐢熺▼搴忚璁″ぇ璧涳紙鍐滃ぇ錛?/title><link>http://www.shnenglu.com/luxiuyuan/archive/2011/09/16/155911.html</link><dc:creator>璺慨榪?/dc:creator><author>璺慨榪?/author><pubDate>Fri, 16 Sep 2011 01:01:00 GMT</pubDate><guid>http://www.shnenglu.com/luxiuyuan/archive/2011/09/16/155911.html</guid><wfw:comment>http://www.shnenglu.com/luxiuyuan/comments/155911.html</wfw:comment><comments>http://www.shnenglu.com/luxiuyuan/archive/2011/09/16/155911.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.shnenglu.com/luxiuyuan/comments/commentRss/155911.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luxiuyuan/services/trackbacks/155911.html</trackback:ping><description><![CDATA[<div style="font-size: 14px" id="blogDetailDiv"> <p>鍐滃ぇ灝辨槸鎶犻棬錛?/p> <p>姣旇禌寮濮嬪墠錛岀珶鐒舵墦鍗版満涓嶈兘鎵撳嵃錛屽歡榪熷崐灝忔椂鎵嶅紕濂斤紒</p> <p>姣旇禌鍓嶏紝绔熺劧娌℃湁鍙戞按錛佺珶鐒惰錛?#8220;娌℃湁姘寸殑鑷繁鍘繪嬁錛?#8221;銆傛劅鎯呮槸瑕佹垜浠嚜宸卞幓涔版按錛屽埆鎷夸粬浠殑錛佸幓鎷跨殑錛屾瘡涓槦涔熷彧鏈変竴鐡?50ml鐨勫▋鍝堝搱錛屼竴涓槦3涓漢錛岃鏄竴涓槦鏈夌敺鏈夊コ錛屽搱鍝?#8230;…榪欎釜澶у閮界煡閬擄紝灝變笉璇翠簡錛?/p> <p>騫稿ソ鎴戜滑鑷繁涔頒簡鍙箰錛?/p> <p>9:30姣旇禌寮濮嬶紒</p> <p>姣旇禌寮濮嬪嚑鍒嗛挓浜嗭紝绔熺劧榪樹笉鍙戠焊璐ㄩ鐩紒闂彁浜ょ綉绔欐槸浠涔堬紝绔熺劧璇村彧鏈夌焊璐ㄧ殑棰樼洰錛屾病鏈夌綉绔欙紒</p> <p>鏃╀笂7鐐瑰悆浜嗕釜闈㈠寘錛屼竴孌墊椂闂翠笅鏉ワ紝楗跨殑涓嶈浜嗐傜粓浜庡埌絳夊埌涓崍浜嗭紝蹇楁効鑰呮嬁鏉ヤ簡鍗堥錛屾墦寮涓鐪嬫垜灝變笉楗夸簡錛?/p> <p>涓涓鏂欒閲屽ご瑁呬簡7涓鐗╋紒涓ょ闈㈠寘錛屽姞璧鋒潵3涓紱涓涓浮铔嬶紱涓ゆ牴涓鍧楅挶鍙互涔頒袱鏍圭殑閭g鐏吙錛涗竴鏍歸钑夛紱涓鐡?50ml鐨勫▋鍝堝搱錛涗竴灝忕摱閰稿ザ錛岀珶鐒舵病鏈夊惛綆★紙鎷垮洖鏉ヤ箣鍚庯紝濂戒笉瀹規槗鎵撳紑錛屼竴闂伙紝绔熺劧涓鑲℃兂鍛曞悙鐨勬劅瑙夋秾涓婁簡蹇冨ご錛屽嚑澶╀笉鏁㈠枬閰稿ザ錛夛紱鎰熸儏鍐滃ぇ涓崍鍚冪殑閮芥槸闈㈠寘錛熷悆绱犵殑錛?/p> <p>鏈濂界殑灝辨槸鏈?縐嶉鐗╋紒7縐嶉鐗╁姞璧鋒潵娌℃湁椋熷爞鍚冧竴嬈¢キ璐碉紒濡傛灉姣忓ぉ鍚冨崍槨愰兘榪欎箞渚垮疁錛屾劅鎯呭氨涓嶈鍘昏繍鍔ㄤ簡錛屼繚鍑嗗噺鑲ワ紒</p> <p>5涓皬鏃惰繃鍘諱簡錛屾瘮璧涚粓浜庡畬浜嗐傚張榪囦簡2涓皬鏃訛紝闂箷寮忕粓浜庡畬浜嗐傝刀绱ц窇鍘誨悆楗紝閭i噷鏁欑粌鏃╁凡璁㈠ソ浜嗛キ錛岀偣濂戒簡鑿滐紒</p> <p>鍧愬湪杞︿笂銆傞粯榛樺湴鍥炲ご鐪嬩簡涓鐪煎啘澶э紒娓愯娓愯繙……</p></div> <img src ="http://www.shnenglu.com/luxiuyuan/aggbug/155911.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luxiuyuan/" target="_blank">璺慨榪?/a> 2011-09-16 09:01 <a href="http://www.shnenglu.com/luxiuyuan/archive/2011/09/16/155911.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>poj 2195 Going Homehttp://www.shnenglu.com/luxiuyuan/archive/2011/04/19/144544.html璺慨榪?/dc:creator>璺慨榪?/author>Tue, 19 Apr 2011 05:54:00 GMThttp://www.shnenglu.com/luxiuyuan/archive/2011/04/19/144544.htmlhttp://www.shnenglu.com/luxiuyuan/comments/144544.htmlhttp://www.shnenglu.com/luxiuyuan/archive/2011/04/19/144544.html#Feedback0http://www.shnenglu.com/luxiuyuan/comments/commentRss/144544.htmlhttp://www.shnenglu.com/luxiuyuan/services/trackbacks/144544.html                                                                                                Going Home

Description

On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent point. For each little man, you need to pay a $1 travel fee for every step he moves, until he enters a house. The task is complicated with the restriction that each house can accommodate only one little man.

Your task is to compute the minimum amount of money you need to pay in order to send these n little men into those n different houses. The input is a map of the scenario, a '.' means an empty space, an 'H' represents a house on that point, and am 'm' indicates there is a little man on that point.

You can think of each point on the grid map as a quite large square, so it can hold n little men at the same time; also, it is okay if a little man steps on a grid with a house without entering that house.

Input

There are one or more test cases in the input. Each case starts with a line giving two integers N and M, where N is the number of rows of the map, and M is the number of columns. The rest of the input will be N lines describing the map. You may assume both N and M are between 2 and 100, inclusive. There will be the same number of 'H's and 'm's on the map; and there will be at most 100 houses. Input will terminate with 0 0 for N and M.

Output

For each test case, output one line with the single integer, which is the minimum amount, in dollars, you need to pay.

Sample Input

2 2
.m
H.
5 5
HH..m
.....
.....
.....
mm..H
7 8
...H....
...H....
...H....
mmmHmmmm
...H....
...H....
...H....
0 0

Sample Output

2
10
28
KM綆楁硶錛?

鍏跺疄榪欎釜棰樻眰鐨勬槸鏈灝忔潈鍖歸厤錛岋紝浣嗘湁浜涢鐩渶灝忎笉涓瀹氬ソ姹傦紝浜庢槸鎴戜滑鍙互鎹竴縐嶆濈淮錛屽皢鏈夋墍鐨勮窛紱誨彉鎴愯礋鐨勶紝閭d箞鎴戜滑瑕佹眰鐨勫氨鏄渶澶ф潈鍖歸厤錛侊紙鍦ㄤ竴浣嶅ぇ鐗涚殑鎸囩偣涓嬶級
搴熻瘽涓嶅璇達紝鐪嬬▼搴忥細
  1 #include<iostream>
  2 using namespace std;
  3 #define Inf 10000000;
  4 int map[105][105];
  5 int slack[105];
  6 int lx[105],ly[105];
  7 bool x[105],y[105];
  8 int link[105];
  9 int n,m;
 10 char mm[105][105];
 11 bool dfs(int v)
 12 {
 13      x[v]=true;
 14      int t;
 15      for (int i=0;i<m;i++)
 16      {
 17          if (!y[i])
 18          {
 19             t=lx[v]+ly[i]-map[v][i];
 20             if (t==0)
 21             {
 22                y[i]=true;
 23                if (link[i]==-1||dfs(link[i]))
 24                {
 25                   link[i]=v;
 26                   return true;
 27                }
 28             }
 29             else slack[i]=min(slack[i],t);
 30          }
 31      }
 32      return false;
 33 }
 34 void KM()
 35 {
 36      int i,j,k;
 37      memset(link,-1,sizeof(link));
 38      for (i=0;i<=m;i++)
 39      {
 40          lx[i]=-Inf;
 41          ly[i]=0;
 42      }
 43      for (i=0;i<m;i++)
 44      {
 45          while (1)
 46          {
 47                memset(x,0,sizeof(x));
 48                memset(y,0,sizeof(y));
 49                
 50                for (j=0;j<m;j++) slack[j]=Inf;
 51                    
 52                if (dfs(i))break;
 53                
 54                int d=Inf;
 55                for (j=0;j<m;j++)
 56                    if (!y[j])d=min(slack[j],d);
 57                    
 58                for (j=0;j<m;j++)
 59                {
 60                    if (x[j])lx[j]-=d;
 61                    if (y[j])ly[j]+=d;
 62                }
 63                for (j=0;j<m;j++)
 64                    if (!y[j])slack[j]-=d;
 65          }
 66      }
 67 }
 68 int main()
 69 {
 70     int i,j,k,t,l,v;
 71     while (cin>>k>>t)
 72     {
 73           if (k+t==0)break;
 74           for (i=1;i<=k;i++)
 75           for (j=1;j<=t;j++)
 76               scanf(" %c",&mm[i][j]);
 77           memset(map,0,sizeof(map));
 78           n=0,m=0;
 79           for (i=1;i<=k;i++)
 80           for (j=1;j<=t;j++)
 81           {
 82               if (mm[i][j]=='H')
 83               {
 84                  n=0;
 85                  for (l=1;l<=k;l++)
 86                  for (v=1;v<=t;v++)
 87                  {
 88                      if (mm[l][v]=='m')
 89                      {
 90                         map[m][n]=-(abs(i-l)+abs(j-v));
 91                         n++;
 92                      }
 93                  }
 94                  m++;
 95               }
 96           }
 97           KM();
 98           int sum=0;
 99           for (i=0;i<m;i++)
100               sum+=map[link[i]][i];
101           cout<<0-sum<<endl;
102     }
103 return 0;
104 }
105  
106 


]]>
poj 3020http://www.shnenglu.com/luxiuyuan/archive/2011/04/05/143433.html璺慨榪?/dc:creator>璺慨榪?/author>Tue, 05 Apr 2011 02:46:00 GMThttp://www.shnenglu.com/luxiuyuan/archive/2011/04/05/143433.htmlhttp://www.shnenglu.com/luxiuyuan/comments/143433.htmlhttp://www.shnenglu.com/luxiuyuan/archive/2011/04/05/143433.html#Feedback0http://www.shnenglu.com/luxiuyuan/comments/commentRss/143433.htmlhttp://www.shnenglu.com/luxiuyuan/services/trackbacks/143433.html闃呰鍏ㄦ枃

]]>
poj 1274http://www.shnenglu.com/luxiuyuan/archive/2011/04/04/143381.html璺慨榪?/dc:creator>璺慨榪?/author>Mon, 04 Apr 2011 01:50:00 GMThttp://www.shnenglu.com/luxiuyuan/archive/2011/04/04/143381.htmlhttp://www.shnenglu.com/luxiuyuan/comments/143381.htmlhttp://www.shnenglu.com/luxiuyuan/archive/2011/04/04/143381.html#Feedback0http://www.shnenglu.com/luxiuyuan/comments/commentRss/143381.htmlhttp://www.shnenglu.com/luxiuyuan/services/trackbacks/143381.html娌′粈涔堝ソ璇寸殑錛岀洿鎺ュ寛鐗欏埄綆楁硶

#include<iostream> 
using namespace std;
int n,m;//n涓簒闆嗗悎錛宮涓簓闆嗗悎 
int map[305][305];//map[x][y]琛ㄧずx,y涓ょ偣涔嬮棿鏈夎竟鐩歌繛 
bool visit[305];//璁板綍m涓殑i鑺傜偣鏄惁琚闂繃 
int link[305];//璁板綍褰撳墠n涓殑i鑺傜偣鏄惁涓?nbsp;j鑺傜偣鐩歌繛 
bool dfs(int a)
{
     
int i;
     
for (i=1;i<=n;i++)
     {
         
if (map[a][i]&&!visit[i])
         {
            visit[i]
=true;
            
if (link[i]==0||dfs(link[i]))
            {
               link[i]
=a;
               
return true;
            }
         }
     }
     
return false;
}
int find()
{
     
int sum=0;
     
for (int i=1;i<=n;i++)
     {
         memset(visit,
0,sizeof(visit));
         
if (dfs(i))sum++;
     }
     
return sum;//鏈澶у尮閰嶆暟 
}
int main()
{
    
int t,i,j,k,x;
    
while (scanf("%d%d",&n,&m)!=EOF)
    {
          memset(map,
0,sizeof(map));
          memset(link,
0,sizeof(link));
          
for (i=1;i<=n;i++)
          {
              scanf(
"%d",&j);
              
for (k=1;k<=j;k++)
              {
                  scanf(
"%d",&x);
                  map[i][x]
=1;
              }  
          }
          cout
<<find()<<endl;
    }
return 0;
}


]]>
hdoj 1175 榪炶繛鐪?/title><link>http://www.shnenglu.com/luxiuyuan/archive/2010/11/24/134519.html</link><dc:creator>璺慨榪?/dc:creator><author>璺慨榪?/author><pubDate>Wed, 24 Nov 2010 08:07:00 GMT</pubDate><guid>http://www.shnenglu.com/luxiuyuan/archive/2010/11/24/134519.html</guid><wfw:comment>http://www.shnenglu.com/luxiuyuan/comments/134519.html</wfw:comment><comments>http://www.shnenglu.com/luxiuyuan/archive/2010/11/24/134519.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luxiuyuan/comments/commentRss/134519.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luxiuyuan/services/trackbacks/134519.html</trackback:ping><description><![CDATA[<p>鍏跺疄榪欎釜棰橈紝鍜屾垜涓婃璁茬殑閭d釜榪炶繛鐪嬩竴鏍鳳紒鍙笉榪囨槸瀛楃鍙樻垚浜嗘暣鍨嬭屽凡錛?br>榪樻槸璐翠竴涓嬪叧閿唬鐮佸惂(鈯檕鈯?~~</p> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">  1</span> <span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> search(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> x1,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> y1,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> x2,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> y2,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> m)<br></span><span style="COLOR: #008080">  2</span> <span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">  3</span> <span style="COLOR: #000000">       memset(gk,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(gk));<br></span><span style="COLOR: #008080">  4</span> <span style="COLOR: #000000">       </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">game[x2][y2];<br></span><span style="COLOR: #008080">  5</span> <span style="COLOR: #000000">       game[x2][y2]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">  6</span> <span style="COLOR: #000000">       gk[x1][y1]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">  7</span> <span style="COLOR: #000000">       <br></span><span style="COLOR: #008080">  8</span> <span style="COLOR: #000000">       </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">瀵筭ame[x1][y1]鍥涗釜鏂瑰悜鏄┖鏍肩殑鏍囦負1 </span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">  9</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">       </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 10</span> <span style="COLOR: #000000">       {<br></span><span style="COLOR: #008080"> 11</span> <span style="COLOR: #000000">             </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(game[i][y1]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)gk[i][y1]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 12</span> <span style="COLOR: #000000">             </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 13</span> <span style="COLOR: #000000">       }<br></span><span style="COLOR: #008080"> 14</span> <span style="COLOR: #000000">      </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">n;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080"> 15</span> <span style="COLOR: #000000">               </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(game[j][y1]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)gk[j][y1]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 16</span> <span style="COLOR: #000000">              </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 17</span> <span style="COLOR: #000000">            }<br></span><span style="COLOR: #008080"> 18</span> <span style="COLOR: #000000">     <br></span><span style="COLOR: #008080"> 19</span> <span style="COLOR: #000000">      </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080"> 20</span> <span style="COLOR: #000000">           </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(game[x1][i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)gk[x1][i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 21</span> <span style="COLOR: #000000">          </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 22</span> <span style="COLOR: #000000">        } <br></span><span style="COLOR: #008080"> 23</span> <span style="COLOR: #000000">     </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">m;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080"> 24</span> <span style="COLOR: #000000">           </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(game[x1][i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)gk[x1][i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 25</span> <span style="COLOR: #000000">          </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 26</span> <span style="COLOR: #000000">          } <br></span><span style="COLOR: #008080"> 27</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080"> 28</span> <span style="COLOR: #000000">     </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">  (gk[x2][y2]</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">gk[x2][y2]</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 29</span> <span style="COLOR: #000000">     {<br></span><span style="COLOR: #008080"> 30</span> <span style="COLOR: #000000">        game[x2][y2]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">t; <br></span><span style="COLOR: #008080"> 31</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 32</span> <span style="COLOR: #000000">     }<br></span><span style="COLOR: #008080"> 33</span> <span style="COLOR: #000000">     </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">瀵筭k[i][j]涓?鐨勫洓涓柟鍚戞槸絀烘牸鐨勬爣涓? </span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080"> 34</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 35</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">m;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 36</span> <span style="COLOR: #000000">          </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">  (gk[i][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 37</span> <span style="COLOR: #000000">          {<br></span><span style="COLOR: #008080"> 38</span> <span style="COLOR: #000000">                </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 39</span> <span style="COLOR: #000000">                {<br></span><span style="COLOR: #008080"> 40</span> <span style="COLOR: #000000">                 </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">  (game[k][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080"> 41</span> <span style="COLOR: #000000">                     </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(gk[k][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)gk[k][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 42</span> <span style="COLOR: #000000">                     }<br></span><span style="COLOR: #008080"> 43</span> <span style="COLOR: #000000">                 </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 44</span> <span style="COLOR: #000000">                 }             <br></span><span style="COLOR: #008080"> 45</span> <span style="COLOR: #000000">             </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">n;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080"> 46</span> <span style="COLOR: #000000">                </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">  (game[k][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080"> 47</span> <span style="COLOR: #000000">                      </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(gk[k][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)gk[k][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 48</span> <span style="COLOR: #000000">                     }<br></span><span style="COLOR: #008080"> 49</span> <span style="COLOR: #000000">                 </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;       <br></span><span style="COLOR: #008080"> 50</span> <span style="COLOR: #000000">                 }<br></span><span style="COLOR: #008080"> 51</span> <span style="COLOR: #000000">             <br></span><span style="COLOR: #008080"> 52</span> <span style="COLOR: #000000">             </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080"> 53</span> <span style="COLOR: #000000">                 </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">  (game[i][k]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080"> 54</span> <span style="COLOR: #000000">                      </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(gk[i][k]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)gk[i][k]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 55</span> <span style="COLOR: #000000">                     }<br></span><span style="COLOR: #008080"> 56</span> <span style="COLOR: #000000">                  </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;       <br></span><span style="COLOR: #008080"> 57</span> <span style="COLOR: #000000">                 }<br></span><span style="COLOR: #008080"> 58</span> <span style="COLOR: #000000">             </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">m;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080"> 59</span> <span style="COLOR: #000000">                </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">  (game[i][k]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080"> 60</span> <span style="COLOR: #000000">                      </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(gk[i][k]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)gk[i][k]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 61</span> <span style="COLOR: #000000">                     }<br></span><span style="COLOR: #008080"> 62</span> <span style="COLOR: #000000">                  </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;       <br></span><span style="COLOR: #008080"> 63</span> <span style="COLOR: #000000">                 }<br></span><span style="COLOR: #008080"> 64</span> <span style="COLOR: #000000">         }<br></span><span style="COLOR: #008080"> 65</span> <span style="COLOR: #000000">       <br></span><span style="COLOR: #008080"> 66</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">  (gk[x2][y2]</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">gk[x2][y2]</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 67</span> <span style="COLOR: #000000">     {<br></span><span style="COLOR: #008080"> 68</span> <span style="COLOR: #000000">        game[x2][y2]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">t; <br></span><span style="COLOR: #008080"> 69</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 70</span> <span style="COLOR: #000000">     }  <br></span><span style="COLOR: #008080"> 71</span> <span style="COLOR: #000000">     </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">瀵筭k[i][j]涓?鐨勫洓涓柟鍚戞槸絀烘牸鐨勬爣涓?</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080"> 72</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">     </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 73</span> <span style="COLOR: #000000">     </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">m;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 74</span> <span style="COLOR: #000000">     </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">  (gk[i][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080"> 75</span> <span style="COLOR: #000000">         </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 76</span> <span style="COLOR: #000000">         {<br></span><span style="COLOR: #008080"> 77</span> <span style="COLOR: #000000">                 </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">  (game[k][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 78</span> <span style="COLOR: #000000">                 {<br></span><span style="COLOR: #008080"> 79</span> <span style="COLOR: #000000">                     </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(gk[k][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)gk[k][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 80</span> <span style="COLOR: #000000">                 }<br></span><span style="COLOR: #008080"> 81</span> <span style="COLOR: #000000">                 </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 82</span> <span style="COLOR: #000000">         }             <br></span><span style="COLOR: #008080"> 83</span> <span style="COLOR: #000000">         </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">n;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 84</span> <span style="COLOR: #000000">         {<br></span><span style="COLOR: #008080"> 85</span> <span style="COLOR: #000000">                 </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">  (game[k][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 86</span> <span style="COLOR: #000000">                 {<br></span><span style="COLOR: #008080"> 87</span> <span style="COLOR: #000000">                      </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(gk[k][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)gk[k][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 88</span> <span style="COLOR: #000000">                 }<br></span><span style="COLOR: #008080"> 89</span> <span style="COLOR: #000000">                  </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;       <br></span><span style="COLOR: #008080"> 90</span> <span style="COLOR: #000000">         }<br></span><span style="COLOR: #008080"> 91</span> <span style="COLOR: #000000">             <br></span><span style="COLOR: #008080"> 92</span> <span style="COLOR: #000000">           </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080"> 93</span> <span style="COLOR: #000000">           {<br></span><span style="COLOR: #008080"> 94</span> <span style="COLOR: #000000">             </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">  (game[i][k]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080"> 95</span> <span style="COLOR: #000000">                     </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(gk[i][k]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)gk[i][k]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080"> 96</span> <span style="COLOR: #000000">                     }<br></span><span style="COLOR: #008080"> 97</span> <span style="COLOR: #000000">                 </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;       <br></span><span style="COLOR: #008080"> 98</span> <span style="COLOR: #000000">             }<br></span><span style="COLOR: #008080"> 99</span> <span style="COLOR: #000000">             </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">m;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">100</span> <span style="COLOR: #000000">             {<br></span><span style="COLOR: #008080">101</span> <span style="COLOR: #000000">                 </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">  (game[i][k]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">102</span> <span style="COLOR: #000000">                 {                                           <br></span><span style="COLOR: #008080">103</span> <span style="COLOR: #000000">                     </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(gk[i][k]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)gk[i][k]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">104</span> <span style="COLOR: #000000">                 }<br></span><span style="COLOR: #008080">105</span> <span style="COLOR: #000000">                  </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;       <br></span><span style="COLOR: #008080">106</span> <span style="COLOR: #000000">             }<br></span><span style="COLOR: #008080">107</span> <span style="COLOR: #000000">           }       <br></span><span style="COLOR: #008080">108</span> <span style="COLOR: #000000">              <br></span><span style="COLOR: #008080">109</span> <span style="COLOR: #000000">         game[x2][y2]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">t;<br></span><span style="COLOR: #008080">110</span> <span style="COLOR: #000000">         </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(gk[x2][y2]</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">gk[x2][y2]</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">111</span> <span style="COLOR: #000000">         </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(gk[x2][y2]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">) </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;  <br></span><span style="COLOR: #008080">112</span> <span style="COLOR: #000000">       }</span></div> <img src ="http://www.shnenglu.com/luxiuyuan/aggbug/134519.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luxiuyuan/" target="_blank">璺慨榪?/a> 2010-11-24 16:07 <a href="http://www.shnenglu.com/luxiuyuan/archive/2010/11/24/134519.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>hdoj 1072 Nightmare!http://www.shnenglu.com/luxiuyuan/archive/2010/11/09/133116.html璺慨榪?/dc:creator>璺慨榪?/author>Tue, 09 Nov 2010 08:59:00 GMThttp://www.shnenglu.com/luxiuyuan/archive/2010/11/09/133116.htmlhttp://www.shnenglu.com/luxiuyuan/comments/133116.htmlhttp://www.shnenglu.com/luxiuyuan/archive/2010/11/09/133116.html#Feedback0http://www.shnenglu.com/luxiuyuan/comments/commentRss/133116.htmlhttp://www.shnenglu.com/luxiuyuan/services/trackbacks/133116.html
 1 #include<iostream>
 2 using namespace std;
 3 int map[12][12],tp[12][12],tt[12][12];
 4 int n,m;
 5 int Min=0xffffff,sum=0;
 6 int x[4]={1,0,0,-1};
 7 int y[4]={0,1,-1,0};
 8 bool f=true;
 9 //鏁扮粍鐨勪氦鎹?nbsp;
10 void fun(int a[12][12],int b[12][12])
11 {
12      for (int i=1;i<=n;i++)
13      for (int j=1;j<=n;j++)
14          a[i][j]=b[i][j];
15 
16 
17 void dfs(int x1,int y1,int sum,int p)
18 {
19      if(map[x1][y1]==3&&p>=0)
20      {
21         // 榪欓噷瑕佹敞鎰忥紝鎴戞槸浠?寮濮嬬殑錛屾悳鍒?鏃訛紝p搴旇鏄?浠ヤ笂錛?br>22         //鍒氬紑濮嬫槸娌℃悶娓呮錛宲澶т簬0,wa浜嗗嚑嬈★紝灝辨槸娌℃壘鍒伴敊璇紒 
23         if(Min>sum)Min=sum;
24         //cout<<sum<<endl;
25         f=false;
26         return;
27      }
28      int dx,dy;
29      for (int i=0;i<4;i++)
30      {
31          dx=x1+x[i];  dy=y1+y[i];
32          if (map[dx][dy]!=0&&tp[dx][dy]==0&&p>=1)
33          {
34             if(map[dx][dy]==4)
35             {
36                map[dx][dy]=0;
37                int temp=p;
38                p=5;
39               // cout<<p<<' '<<dx<<' '<<dy<<endl;
40               //杈撳嚭璺緞錛屽亸浜庢煡鎵懼綋鍓嶇殑鍧愭爣浣嶇疆鍜屽墿浣欐椂闂磒 
41                fun(tt,tp);
42                memset(tp,0,sizeof(tp));
43                //鍒?鏄彲浠ュ線鍥炴悳鐨勶紝鎵浠ュ墠闈㈢殑璧拌繃鐨勮礬寰勫簲璇ョЩ闄ゆ爣璁?br>44                //鐢ㄦ暟緇則t璁頒綇鍓嶉潰璧拌繃鐨勮礬寰勶紝浠ヤ究浜庡悗闈㈢殑鎼滅儲 
45                tp[dx][dy]=1;
46                dfs(dx,dy,sum+1,p);
47                //鍑烘潵娣風殑錛屾槸瑕佽繕鐨勶紒榪欓噷涔熶竴鏍鳳紒 
48                map[dx][dy]=4;
49                tp[dx][dy]=0;
50                p=temp;
51                fun(tp,tt);
52             }
53             else
54             {
55                 tp[dx][dy]=1;
56                 //cout<<"->"<<p<<' '<<dx<<' '<<dy<<endl;
57                 //杈撳嚭璺緞錛屽亸浜庢煡鎵懼綋鍓嶇殑鍧愭爣浣嶇疆鍜屽墿浣欐椂闂磒 
58                 dfs(dx,dy,sum+1,p-1);
59                 tp[dx][dy]=0;
60             }   
61          }    
62      }
63 }
64 int main()
65 {
66     int t;
67     cin>>t;
68     while (t--)
69     {
70           memset(map,0,sizeof(map));
71           memset(tp,0,sizeof(tp));
72           cin>>n>>m;
73           f=true;
74           int x1,y1,x2,y2;
75           for (int i=1;i<=n;i++)
76           for (int j=1;j<=m;j++)
77           {
78               cin>>map[i][j];
79               if(map[i][j]==2)x1=i,y1=j;
80               //if(map[i][j]==3)x2=i,y2=j;                   
81           }
82           Min=0xffffff,sum=0;
83           int p=5;
84           map[x1][y1]=0;
85           dfs(x1,y1,sum,5);
86           if(!f)cout<<Min<<endl;
87           else cout<<-1<<endl;
88     }
89 return 0;
90 }
91 


]]>
婷婷久久久亚洲欧洲日产国码AV| 国产一久久香蕉国产线看观看| 亚洲国产二区三区久久| 亚洲国产精品高清久久久| 日韩精品久久久肉伦网站 | 久久无码精品一区二区三区| 人妻少妇久久中文字幕| 久久久久久极精品久久久 | 久久久久青草线蕉综合超碰| 99热精品久久只有精品| 欧美日韩中文字幕久久伊人| jizzjizz国产精品久久| 国产叼嘿久久精品久久| 亚洲国产精品久久久久久| 国产日产久久高清欧美一区| 久久se精品一区二区| 国产美女久久久| 亚洲欧美日韩精品久久| 久久国产欧美日韩精品免费| 狠狠精品久久久无码中文字幕| 亚洲午夜久久久精品影院| 亚洲欧美日韩久久精品| 久久精品亚洲精品国产色婷| 伊人色综合久久| 国产精品热久久毛片| 亚洲综合精品香蕉久久网| 色综合久久久久久久久五月| 久久精品国产亚洲av麻豆小说| 91精品国产高清久久久久久91| 久久久久久免费视频| 99久久精品国内| 国产激情久久久久影院老熟女免费| 亚洲欧美日韩精品久久亚洲区| 久久久精品免费国产四虎| 国产成人精品久久一区二区三区av| 亚洲AⅤ优女AV综合久久久| 久久精品青青草原伊人| 久久国产免费观看精品| 久久成人18免费网站| 日韩精品久久无码中文字幕| 久久精品桃花综合|