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

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)練里初級中最后一個MST的題目了
鴨梨好大……
題目果斷沒看懂啊
不過看他的樣例,隱約猜到了做法
任意兩個點之間的距離(floodfill),然后求最小生成樹
然后去找翻譯,果然跟我想的一樣
任意兩點的距離怎么求呢,對每一點floodfill 因為是bfs嘛,所以最先得到的距離就是某一點距離這一點的最短距離
這樣做效率不高,因為任意兩點之間的距離是一定的,所以任意兩點的距離都被求了兩邊
沒想到什么好的優(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) 評論(0)  編輯 收藏 引用


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


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

導(dǎo)航

統(tǒng)計

常用鏈接

留言簿

文章檔案(85)

搜索

最新評論

  • 1.?re: poj1426
  • 我嚓,,輝哥,,居然搜到你的題解了
  • --season
  • 2.?re: poj3083
  • @王私江
    (8+i)&3 相當(dāng)于是 取余3的意思 因為 3 的 二進(jìn)制是 000011 和(8+i)
  • --游客
  • 3.?re: poj3414[未登錄]
  • @王私江
    0ms
  • --jh818012
  • 4.?re: poj3414
  • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
  • --王私江
  • 5.?re: poj1426
  • 評論內(nèi)容較長,點擊標(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>
            亚洲香蕉视频| 美女诱惑一区| 久久激情中文| 午夜精品国产精品大乳美女| 欧美日韩dvd在线观看| 亚洲国产成人精品女人久久久| 国产九九精品视频| 亚洲一区二区三区视频| 亚洲一区二区少妇| 欧美日韩在线观看视频| 一区二区三区欧美日韩| 亚洲欧美日韩电影| 国产手机视频精品| 欧美在线影院| 欧美不卡视频一区发布| 亚洲精品视频免费在线观看| 欧美激情综合五月色丁香| 亚洲肉体裸体xxxx137| 一区二区三区福利| 国产精品久久久久久久7电影 | 欧美一区激情视频在线观看| 国产欧美精品国产国产专区| 性欧美video另类hd性玩具| 久久久激情视频| 亚洲高清在线精品| 欧美日韩精品综合在线| 亚洲一区国产| 六月婷婷久久| 99在线视频精品| 国产精品高清在线| 欧美成人一区二区三区片免费| 国产精品一区视频网站| 亚洲欧美国产日韩天堂区| 久久精品女人天堂| 一区三区视频| 欧美国产日产韩国视频| 一本大道久久精品懂色aⅴ | 国产精品久久久久一区二区| 亚洲欧美日韩综合aⅴ视频| 久久久久国产精品厨房| 在线观看欧美日韩国产| 欧美va亚洲va国产综合| 日韩视频在线观看国产| 性做久久久久久| 亚洲高清久久久| 欧美日韩你懂的| 午夜在线精品偷拍| 亚洲国产精品第一区二区三区| 国产日本欧洲亚洲| 樱花yy私人影院亚洲| 久久久久久一区| 亚洲激情在线观看| 欧美一级大片在线免费观看| 精东粉嫩av免费一区二区三区| 欧美成人精品高清在线播放| 一区二区三区高清在线观看| 开心色5月久久精品| 一区二区三区不卡视频在线观看| 国产午夜精品全部视频播放| 欧美精品三级日韩久久| 欧美亚洲日本国产| 亚洲人成在线观看一区二区| 久久久精品国产99久久精品芒果| 99热这里只有精品8| 好吊色欧美一区二区三区四区| 欧美精品免费在线| 久久精品中文| 亚洲欧美日韩精品久久久| 亚洲精品系列| 欧美成人一区二区| 久久国产精品99精品国产| 99精品99久久久久久宅男| 久久亚洲精品一区二区| 99在线精品观看| 麻豆国产精品一区二区三区| 亚洲天堂成人| 亚洲黄一区二区| 国产欧美日韩一区| 国产精品爱久久久久久久| 男男成人高潮片免费网站| 久久99伊人| 亚洲欧美bt| 一区二区三区日韩欧美| 亚洲国产精品一区| 免费在线欧美视频| 久久夜色精品国产欧美乱| 欧美在线综合| 欧美一区二区三区在线免费观看| 一区二区不卡在线视频 午夜欧美不卡在 | 最新日韩av| 美脚丝袜一区二区三区在线观看| 亚洲欧美日韩在线| 亚洲一本大道在线| 一区二区三区国产在线| 亚洲美女少妇无套啪啪呻吟| 亚洲国产成人av好男人在线观看| 国内精品久久久久影院色| 国产丝袜美腿一区二区三区| 国产精品色午夜在线观看| 欧美视频中文字幕| 欧美午夜精品电影| 欧美色道久久88综合亚洲精品| 欧美激情精品久久久久久久变态 | 你懂的视频欧美| 免费日本视频一区| 免费日韩av电影| 欧美成人免费观看| 欧美激情视频一区二区三区免费| 欧美激情第一页xxx| 欧美日本亚洲视频| 香蕉av777xxx色综合一区| 久热爱精品视频线路一| 欧美一区午夜精品| 久久九九热免费视频| 久久国产加勒比精品无码| 久久九九99| 免费成人高清| 欧美精品一区二区三区久久久竹菊 | 久久精品视频免费观看| 久久国产精品久久w女人spa| 久久久久久久久久久久久9999| 久久久不卡网国产精品一区| 久久综合久久久| 欧美激情中文不卡| 国产精品免费一区二区三区在线观看| 国产乱码精品一区二区三区不卡| 国产一区二区精品| 最新亚洲激情| 亚洲综合日韩中文字幕v在线| 香蕉久久a毛片| 麻豆精品在线观看| 亚洲看片一区| 午夜精品亚洲一区二区三区嫩草| 久久精品视频免费观看| 欧美精品亚洲| 国产女人18毛片水18精品| 伊人久久婷婷色综合98网| 99视频一区二区三区| 久久er99精品| 亚洲日本国产| 欧美一区二区三区另类| 亚洲第一天堂无码专区| 亚洲福利国产精品| 一区二区免费在线播放| 欧美一区二区三区在线播放| 久久综合免费视频影院| 欧美日韩视频在线| 国产一区二区精品| 日韩一区二区精品视频| 久久久久国产一区二区三区四区 | 欧美福利一区二区三区| 在线亚洲精品| 久久先锋影音| 国产精品亚洲一区二区三区在线| 激情婷婷亚洲| 亚洲午夜伦理| 欧美大胆成人| 欧美一级在线播放| 欧美先锋影音| 亚洲精品欧美极品| 久久伊人亚洲| 亚洲视频在线观看一区| 免费高清在线一区| 国产精品专区一| 在线视频日韩精品| 欧美**字幕| 亚洲欧美偷拍卡通变态| 欧美日韩视频免费播放| 亚洲精品美女91| 美女任你摸久久| 性xx色xx综合久久久xx| 欧美日韩在线一区| 亚洲精品美女免费| 麻豆av一区二区三区| 亚洲欧美日韩综合一区| 国产精品电影观看| 一区二区激情小说| 亚洲福利视频二区| 久久久久久网站| 国产综合香蕉五月婷在线| 亚洲欧美综合另类中字| 99亚洲一区二区| 欧美精品免费在线| 亚洲精品偷拍| 免费在线播放第一区高清av| 欧美在线视频二区| 国产欧美在线观看一区| 亚洲尤物影院| 一区二区三区国产在线| 欧美日韩国产首页在线观看| 亚洲精品国产欧美| 欧美黄色免费| 欧美va亚洲va国产综合| 亚洲裸体俱乐部裸体舞表演av| 欧美aaaaaaaa牛牛影院| 久久阴道视频| 91久久精品美女高潮| 欧美国产精品久久| 蜜臀va亚洲va欧美va天堂| 91久久综合|