青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

poj3026

Borg Maze

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4902 Accepted: 1659

Description

The Borg is an immensely powerful race of enhanced humanoids from the delta quadrant of the galaxy. The Borg collective is the term used to describe the group consciousness of the Borg civilization. Each Borg individual is linked to the collective by a sophisticated subspace network that insures each member is given constant supervision and guidance.

Your task is to help the Borg (yes, really) by developing a program which helps the Borg to estimate the minimal cost of scanning a maze for the assimilation of aliens hiding in the maze, by moving in north, west, east, and south steps. The tricky thing is that the beginning of the search is conducted by a large group of over 100 individuals. Whenever an alien is assimilated, or at the beginning of the search, the group may split in two or more groups (but their consciousness is still collective.). The cost of searching a maze is definied as the total distance covered by all the groups involved in the search together. That is, if the original group walks five steps, then splits into two groups each walking three steps, the total distance is 11=5+3+3.

Input

On the first line of input there is one integer, N <= 50, giving the number of test cases in the input. Each test case starts with a line containg two integers x, y such that 1 <= x,y <= 50. After this, y lines follow, each which x characters. For each character, a space `` '' stands for an open space, a hash mark ``#'' stands for an obstructing wall, the capital letter ``A'' stand for an alien, and the capital letter ``S'' stands for the start of the search. The perimeter of the maze is always closed, i.e., there is no way to get out from the coordinate of the ``S''. At most 100 aliens are present in the maze, and everyone is reachable.

Output

For every test case, output one line containing the minimal cost of a succesful search of the maze leaving no aliens alive.

Sample Input

2
6 5
##### 
#A#A##
# # A#
#S  ##
##### 
7 7
#####  
#AAA###
#    A#
# S ###
#     #
#AAA###
#####  

Sample Output

8
11
 
這是ACM算法訓(xùn)練里初級(jí)中最后一個(gè)MST的題目了
鴨梨好大……
題目果斷沒(méi)看懂啊
不過(guò)看他的樣例,隱約猜到了做法
任意兩個(gè)點(diǎn)之間的距離(floodfill),然后求最小生成樹(shù)
然后去找翻譯,果然跟我想的一樣
任意兩點(diǎn)的距離怎么求呢,對(duì)每一點(diǎn)floodfill 因?yàn)槭莃fs嘛,所以最先得到的距離就是某一點(diǎn)距離這一點(diǎn)的最短距離
這樣做效率不高,因?yàn)槿我鈨牲c(diǎn)之間的距離是一定的,所以任意兩點(diǎn)的距離都被求了兩邊
沒(méi)想到什么好的優(yōu)化方法
1次AC 挺爽的
 
  1#include<stdio.h>
  2#include<string.h>
  3#include<math.h>
  4#define MAX 150
  5struct node
  6{
  7    int x,y,s;
  8}
;
  9int dx[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};
 10int n,m,ans;
 11short map[55][55];
 12int num,dis[MAX][MAX];
 13void init()
 14{
 15    int i,j;
 16    char tmp[100];
 17    scanf("%d%d",&m,&n);
 18    gets(tmp);
 19    num=1;
 20    for (i=0; i<n ; i++ )
 21    {
 22        gets(tmp);
 23        for (j=0; j<m ; j++ )
 24        {
 25            if (tmp[j]=='#') map[i][j]=-1;
 26            else if (tmp[j]==' ') map[i][j]=0;
 27            else if (tmp[j]=='S') map[i][j]=1;
 28            else if (tmp[j]=='A')
 29            {
 30                num++;
 31                map[i][j]=num;
 32            }

 33        }

 34    }

 35}

 36void bfs(int x,int y)
 37{
 38    int head,tail,i,j;
 39    short flag[55][55];
 40    struct node q[3000],now,nn;
 41    head=0;
 42    tail=1;
 43    q[tail].x=x;
 44    q[tail].y=y;
 45    q[tail].s=0;
 46    memset(flag,0,sizeof(flag));
 47    flag[x][y]=1;
 48    while (head!=tail)
 49    {
 50        head++;
 51        now=q[head];
 52        for (i=0; i<4 ; i++ )
 53        {
 54            nn.x=now.x+dx[i][0];
 55            nn.y=now.y+dx[i][1];
 56            if ((nn.x>=0)&&(nn.x<n)&&(nn.y>=0)&&(nn.y<m)&&(!flag[nn.x][nn.y])&&(map[nn.x][nn.y]>=0))
 57            {
 58                nn.s=now.s+1;
 59                tail++;
 60                flag[nn.x][nn.y]=1;
 61                q[tail]=nn;
 62                if (map[nn.x][nn.y]>0)
 63                {
 64                    dis[map[x][y]][map[nn.x][nn.y]]=nn.s;
 65                    dis[map[nn.x][nn.y]][map[x][y]]=nn.s;
 66                }

 67            }

 68        }

 69    }

 70}

 71void prim()
 72{
 73    int cost[MAX];
 74    short vis[MAX];
 75    int min,mini,i,j;
 76    memset(vis,0,sizeof(vis));
 77    for (i=2; i<=num; i++) cost[i]=dis[1][i];
 78    vis[1]=1;
 79    ans=0;
 80    cost[1]=0;
 81    for (i=1; i<=num-1 ; i++ )
 82    {
 83        min=0x7fffffff;
 84        for (j=1; j<=num; j++ )
 85            if ((!vis[j])&&(cost[j]<min))
 86            {
 87                min=cost[j];
 88                mini=j;
 89            }

 90        ans=ans+min;
 91        vis[mini]=1;
 92        for (j=1; j<=num ; j++ )
 93            if ((!vis[j])&&(dis[mini][j]>0)&&(cost[j]>dis[mini][j]))
 94            {
 95                cost[j]=dis[mini][j];
 96            }

 97    }

 98}

 99void work()
100{
101    int i,j;
102    ans=0;
103    memset(dis,0,sizeof(dis));
104    for (i=0; i<n ; i++ )
105        for (j=0; j<n ; j++ )
106            if (map[i][j]>0)
107            {
108                bfs(i,j);
109            }

110    prim();
111    printf("%d\n",ans);
112}

113int main()
114{
115    int t;
116    scanf("%d",&t);
117    while (t)
118    {
119        init();
120        work();
121        t--;
122    }

123    return 0;
124}

125

posted on 2012-02-15 15:29 jh818012 閱讀(339) 評(píng)論(0)  編輯 收藏 引用


只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


<2025年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

留言簿

文章檔案(85)

搜索

最新評(píng)論

  • 1.?re: poj1426
  • 我嚓,,輝哥,,居然搜到你的題解了
  • --season
  • 2.?re: poj3083
  • @王私江
    (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
  • --游客
  • 3.?re: poj3414[未登錄](méi)
  • @王私江
    0ms
  • --jh818012
  • 4.?re: poj3414
  • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
  • --王私江
  • 5.?re: poj1426
  • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
  • --王私江
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产视频综合在线| 日韩亚洲欧美综合| 美女视频一区免费观看| 亚洲图中文字幕| 欧美激情中文不卡| 久久精品女人| 亚洲综合电影| 99综合精品| 亚洲高清毛片| 影音先锋在线一区| 国产偷国产偷精品高清尤物| 欧美日韩一区二| 欧美成人免费大片| 久久裸体艺术| 欧美亚洲在线视频| 亚洲午夜羞羞片| 亚洲欧洲一区二区三区久久| 国产日韩精品在线| 国产精品一区二区久久| 欧美肉体xxxx裸体137大胆| 欧美**人妖| 欧美1区视频| 欧美aa国产视频| 美女精品在线| 欧美xx69| 欧美激情亚洲另类| 欧美激情综合在线| 欧美精品一区二区三| 欧美韩国日本综合| 欧美精品一区二区三区蜜桃 | 欧美日韩高清一区| 欧美韩日精品| 欧美成人亚洲成人| 欧美激情久久久久久| 欧美精品日本| 欧美日韩美女一区二区| 欧美久久电影| 欧美日韩一区在线| 国产精品国产三级国产专播品爱网 | 欧美韩国日本一区| 欧美日本亚洲| 欧美日韩国产综合视频在线观看| 欧美老女人xx| 国产精品videosex极品| 国产精品最新自拍| 国产亚洲美州欧州综合国| 国模精品娜娜一二三区| 在线播放豆国产99亚洲| 亚洲国产成人在线| 日韩午夜中文字幕| 亚洲午夜羞羞片| 欧美伊人久久久久久久久影院| 久久激情网站| 欧美电影免费观看高清| 亚洲精品国久久99热| 亚洲电影欧美电影有声小说| 日韩视频在线观看免费| 亚洲综合日韩中文字幕v在线| 欧美一区二区在线播放| 免费人成精品欧美精品| 欧美日韩在线第一页| 国产欧美综合在线| 亚洲福利视频免费观看| 一区二区三区av| 欧美中文字幕精品| 欧美激情精品久久久六区热门| 亚洲免费大片| 欧美一区视频| 欧美激情第三页| 国产目拍亚洲精品99久久精品 | 久久高清福利视频| 欧美国产日产韩国视频| 国产精品美女黄网| 亚洲成人资源| 亚洲一区二区成人在线观看| 久久精品国产亚洲精品| 亚洲国产精品一区二区www在线| a4yy欧美一区二区三区| 羞羞色国产精品| 欧美成人免费小视频| 国产精品区一区二区三区| 亚洲成人资源| 欧美亚洲一区二区在线观看| 欧美国产一区视频在线观看 | 蜜桃av一区| 国产精品久久久一本精品| 伊人伊人伊人久久| 亚洲一区二区黄| 欧美成人免费全部观看天天性色| 夜夜嗨av色综合久久久综合网| 欧美在线关看| 亚洲欧美一区二区激情| 毛片av中文字幕一区二区| 国产精品理论片| 亚洲精品四区| 久久亚洲一区二区| 亚洲天堂网站在线观看视频| 欧美96在线丨欧| 国产综合精品| 午夜精品久久久久久久99黑人| 欧美护士18xxxxhd| 欧美一区激情| 国产精品黄色| 99国内精品久久| 美女国产精品| 性感少妇一区| 国产精品美女久久久久av超清| 亚洲激情精品| 久久夜色精品国产亚洲aⅴ| 亚洲香蕉伊综合在人在线视看| 欧美精品久久久久久久久久| 久久亚洲国产成人| 亚洲深夜激情| 久久婷婷国产综合尤物精品| 欧美吻胸吃奶大尺度电影| 韩国精品一区二区三区| 午夜视频在线观看一区二区| 亚洲国产精彩中文乱码av在线播放| 亚洲精品欧美一区二区三区| 亚洲一区二区久久| 欧美成人第一页| 国产欧美日韩另类视频免费观看| 久久久亚洲人| 欧美日韩亚洲一区二区三区在线观看| 亚洲激情不卡| 亚洲欧美乱综合| 亚洲制服欧美中文字幕中文字幕| 欧美伦理在线观看| 精品成人在线| 欧美中文字幕不卡| 亚洲国产美女久久久久| 欧美另类久久久品| 一区二区亚洲欧洲国产日韩| 久久久夜精品| 久久久久国产精品麻豆ai换脸| 国产亚洲毛片在线| 鲁大师成人一区二区三区| 久久精品国产精品| 国产精品美女久久久久久2018| 在线观看免费视频综合| 国产精品99久久99久久久二8 | 久久人人爽人人爽爽久久| 亚洲免费一在线| 欧美激情 亚洲a∨综合| 在线国产精品播放| 久久久97精品| 午夜精品久久久久99热蜜桃导演| 国产精品乱人伦一区二区| 亚洲高清久久久| 欧美亚洲综合在线| 麻豆成人综合网| 亚洲女ⅴideoshd黑人| 黄色一区二区在线观看| 久久精品视频免费| 免费观看久久久4p| 欧美色综合天天久久综合精品| 韩国视频理论视频久久| 亚洲天堂视频在线观看| 欧美大片免费久久精品三p| 日韩一区二区精品| 欧美大片18| 亚洲乱码国产乱码精品精| 亚洲激情av在线| 欧美黄在线观看| 亚洲一区二区免费视频| 亚洲午夜小视频| 国产日韩成人精品| 久久久噜噜噜久噜久久 | 亚洲一区二区三区四区在线观看 | 亚洲精品在线视频观看| 欧美一区二区久久久| 国产精品久久久久影院色老大 | 久久久久一本一区二区青青蜜月| 亚洲欧美综合v| 欧美成人r级一区二区三区| 美女日韩在线中文字幕| 午夜国产一区| …久久精品99久久香蕉国产| 老鸭窝毛片一区二区三区| 欧美一区二区三区婷婷月色 | 亚洲永久在线观看| 国产亚洲福利社区一区| 美玉足脚交一区二区三区图片| 欧美成人在线免费观看| 亚洲伊人久久综合| 久久国产精品久久国产精品| 亚洲片在线观看| 亚洲午夜精品一区二区三区他趣| 激情六月婷婷综合| 亚洲精品国产视频| 国产噜噜噜噜噜久久久久久久久| 免费影视亚洲| 国产精品久久久久久久久借妻 | 亚洲一区二区三区乱码aⅴ蜜桃女| 国模大胆一区二区三区| 亚洲伦理在线观看| 精品成人一区二区三区| 亚洲小说春色综合另类电影| 91久久综合| 欧美一二三视频|