锘??xml version="1.0" encoding="utf-8" standalone="yes"?>精品国产乱码久久久久软件,久久精品国产亚洲AV蜜臀色欲,欧美一级久久久久久久大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#Feedback8http://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 

   

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


]]>
涔濆濉暟婧愪唬鐮乧++http://www.shnenglu.com/luxiuyuan/archive/2010/06/30/118956.html璺慨榪?/dc:creator>璺慨榪?/author>Wed, 30 Jun 2010 00:14:00 GMThttp://www.shnenglu.com/luxiuyuan/archive/2010/06/30/118956.htmlhttp://www.shnenglu.com/luxiuyuan/comments/118956.htmlhttp://www.shnenglu.com/luxiuyuan/archive/2010/06/30/118956.html#Feedback0http://www.shnenglu.com/luxiuyuan/comments/commentRss/118956.htmlhttp://www.shnenglu.com/luxiuyuan/services/trackbacks/118956.html“涔濆濉暟“涔熷彨“涔濇柟鏁?#8221;錛屽彜浠gО涓?#8220;涔濆綆?#8221;銆備節瀹~鏁版槸灝嗕節涓湁鏁堟暟瀛楀~鍦ㄤ節涓柟浣嶆牸瀛愰噷錛岃浣挎瘡琛屻佹瘡鍒楀拰姣忔潯瀵硅綰夸笂鐨勫拰閮界浉絳夛紝鍗籌細妯殑涓変釜鏁頒箣鍜屻佺珫鐨勪笁涓暟涔嬪拰涓庢枩鐨勪笁涓暟涔嬪拰錛岄兘鐩哥瓑銆傚湪瑙h繖涓涔嬪墠錛屽厛鎶婁節瀹殑鏂逛綅闂鏄庣‘浜嗭紝浠ヤ究璁茶鍏蜂綋鐨勯槓榪般?span style="FONT-SIZE: 12pt; FONT-FAMILY: '瀹嬩綋'; mso-spacerun: 'yes'">

銆銆榪欎釜鏂逛綅鐨勭‘瀹氫笌鐪嬪湴鍥劇殑鏂逛綅鏄竴鑷寸殑銆傜敱浜庤鎶?鈥?榪欎節涓暟濉湪閫傚綋鐨勬牸瀛愰噷錛岃繖涔濅釜鏁頒箣鍜屾槸45錛屾棤璁烘槸妯佺珫銆佹枩閮芥槸涓変釜鏁幫紝鎶?5騫沖潎鍒嗘垚涓夎錛屾瘡琛屼笁涓暟鐨勫拰閮芥槸15錛堝寘鎷í銆佺珫銆佹枩錛夈傛瘡涓変釜鏁扮殑鎯呭喌錛氭í鏈?縐嶏紝绔栨湁3縐嶏紝鏂滄湁2縐嶏紝鍏?縐嶃?/span>




鍙鐭ラ亾涓変釜鏁板氨鍙互鏋氫婦鎵鏈夌殑鏁頒簡錛?br>

 

I

J

 

 

5

 

 

 

 

 1 #include<iostream>
 2 using namespace std;
 3 int b[10],a[10];
 4 int main(){
 5     int f = 0;
 6     for (int i=1;i<10;i++){        
 7         if(i!=5)b[1]=i;
 8         for (int j=1;j<10;j++)
 9         {
10             b[5= 5;
11              if(j!=i&&j!=5&&i!=5){
12               b[2= j;
13               b[8= 15 - b[2- b[5];
14               b[3= 15 - b[1- b[2];
15               b[9= 15 - b[1- b[5];
16               b[7= 15 - b[3- b[5];
17               b[4= 15 - b[1- b[7];              
18               b[6= 15 - b[3- b[9];
19               if(b[4]+b[5]+b[6]==15&&b[7]+b[8]+b[9]==15)
20               {
21                     f = 0;
22                     memset(a,0,sizeof(a));
23                   for (int k=1;k<10;k++)  a[b[k]]++;
24                      for (int k=1;k<10;k++)  if(a[k]<=0||a[k]>1){f = 1;break;}
25                   if(f==0){ 
26                       for (int k=1;k<10;k++)
27                       {
28                            cout<< b[k] <<' ';
29                            if(k%3==0)cout << endl;
30                         }
31                     cout << endl;
32                     }
33                    }
34             }
35          }        
36      }
37     system("pause");
38     return 0;
39     }
40 


]]>
HDU 1211 RSAhttp://www.shnenglu.com/luxiuyuan/archive/2010/06/26/118785.html璺慨榪?/dc:creator>璺慨榪?/author>Sat, 26 Jun 2010 10:59:00 GMThttp://www.shnenglu.com/luxiuyuan/archive/2010/06/26/118785.htmlhttp://www.shnenglu.com/luxiuyuan/comments/118785.htmlhttp://www.shnenglu.com/luxiuyuan/archive/2010/06/26/118785.html#Feedback0http://www.shnenglu.com/luxiuyuan/comments/commentRss/118785.htmlhttp://www.shnenglu.com/luxiuyuan/services/trackbacks/118785.htmlProblem Description
RSA is one of the most powerful methods to encrypt data. The RSA algorithm is described as follow:

> choose two large prime integer p, q
> calculate n = p × q, calculate F(n) = (p - 1) × (q - 1)
> choose an integer e(1 < e < F(n)), making gcd(e, F(n)) = 1, e will be the public key
> calculate d, making d × e mod F(n) = 1 mod F(n), and d will be the private key

You can encrypt data with this method :

C = E(m) = me mod n

When you want to decrypt data, use this method :

M = D(c) = cd mod n

Here, c is an integer ASCII value of a letter of cryptograph and m is an integer ASCII value of a letter of plain text.

Now given p, q, e and some cryptograph, your task is to "translate" the cryptograph into plain text.
 

Input
Each case will begin with four integers p, q, e, l followed by a line of cryptograph. The integers p, q, e, l will be in the range of 32-bit integer. The cryptograph consists of l integers separated by blanks.
 

Output
For each case, output the plain text in a single line. You may assume that the correct result of plain text are visual ASCII letters, you should output them as visualable letters with no blank between them.
 

Sample Input
101 103 7 11 7716 7746 7497 126 8486 4708 7746 623 7298 7357 3239
 

Sample Output
I-LOVE-ACM.
浠ヤ負瑕佹暟緇勶紝鎯蟲兂錛屼笉鏄偅涔堝洖浜嬶紒

鎸虹畝鍗曠殑~~
 1 #include<iostream>
 2 using namespace std;
 3 int main(){
 4     int p,q,e,t;
 5     while (cin>>p>>q>>e>>t)
 6     {
 7            int n = p*q,fn = (p-1)*(q-1);
 8            int d =1;
 9            while ((d*e)%fn!=1)d++;
10           int c;
11           for (int i=0;i<t;i++)
12           {
13                  cin>>c;
14                  int temp=1;
15                  for (int j=1;j<=d;j++)
16                  {
17                      temp*=c;
18                      temp%=n;
19                   }
20                 cout<<char(temp); 
21                  }
22            cout<<endl;
23            }    
24     return 0;
25     }


]]>
99久久国产综合精品麻豆| 欧美午夜A∨大片久久 | 久久国产精品一区| 综合久久给合久久狠狠狠97色 | 亚洲国产精品成人久久| AV无码久久久久不卡网站下载 | 久久精品男人影院| 久久91精品国产91久| 99久久人妻无码精品系列 | 久久99免费视频| 99久久综合国产精品免费| 亚洲嫩草影院久久精品| 国内精品人妻无码久久久影院导航| 精品久久一区二区三区| 亚洲精品乱码久久久久久蜜桃不卡 | 久久精品国产一区二区三区不卡 | 国产午夜电影久久| 久久香蕉国产线看观看精品yw| 久久播电影网| 久久青青草原精品影院| 亚洲中文久久精品无码ww16| 成人国内精品久久久久影院VR| 少妇高潮惨叫久久久久久| 亚洲国产精品综合久久网络| 国产高潮久久免费观看| 久久99国产精品99久久| 久久久久久亚洲Av无码精品专口 | 久久99国产精品久久99| 国产91久久精品一区二区| 亚洲AV日韩AV永久无码久久| 久久久国产精华液| 久久精品aⅴ无码中文字字幕不卡| 日本久久中文字幕| 久久精品无码av| 久久精品国产只有精品66| 久久久久久国产精品无码下载 | 狠狠色丁香久久婷婷综合_中 | 综合久久久久久中文字幕亚洲国产国产综合一区首 | 亚洲欧洲精品成人久久曰影片 | 99精品伊人久久久大香线蕉| 精品久久久久久久|