POJ3026 Borg Maze 2017-04-21 16:02 50人阅读 评论(0) 收藏
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 14165 | Accepted: 4619 |
Description
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
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
Sample Input
2
6 5
#####
#A#A##
# # A#
#S ##
#####
7 7
#####
#AAA###
# A#
# S ###
# #
#AAA###
#####
Sample Output
8
11
Source
#include <iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<cstring>
using namespace std;
#define LL long long struct node
{
int u,v,w;
} p[1000005]; struct point
{
int x,y,t;
}; char mp[105][105];
int dir[4][2]= {{0,1},{0,-1},{1,0},{-1,0}};
int vis[105][105]; int n,m,cnt,tot,pre[10005]; bool cmp(node a,node b)
{
return a.w<b.w;
}
void init()
{
for(int i=0; i<10005; i++)
pre[i]=i;
} int fin(int x)
{
return pre[x]==x?x:pre[x]=fin(pre[x]);
} void kruskal()
{
sort(p,p+cnt,cmp);
init();
int cost=0;
int ans=0;
for(int i=0; i<cnt; i++)
{
int a=fin(p[i].u);
int b=fin(p[i].v);
if(a!=b)
{
pre[a]=b;
cost+=p[i].w;
ans++;
}
if(ans==tot-1)
{
break;
}
}
printf("%d\n",cost);
} bool check(int x,int y)
{
if(x<0||x>=n||y<0||y>=m||mp[x][y]=='#')
return 0;
return 1;
} void build(int x,int y)
{
memset(vis,0,sizeof vis);
point f,d;
f.x=x;
f.y=y;
f.t=0;
vis[x][y]=1;
queue<point>q;
q.push(f);
while(!q.empty())
{
f=q.front();
q.pop();
if((mp[f.x][f.y]=='A'||mp[f.x][f.y]=='S')&&(f.x!=x||f.y!=y))
{
p[cnt].u=100*x+y;
p[cnt].v=100*f.x+f.y;
p[cnt++].w=f.t;
}
for(int i=0; i<4; i++)
{
int xx=f.x+dir[i][0];
int yy=f.y+dir[i][1];
if(!vis[xx][yy]&&check(xx,yy))
{
d.x=xx;
d.y=yy;
d.t=f.t+1;
vis[xx][yy]=1;
q.push(d);
}
}
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&m,&n);
char temp[51];
gets(temp);
for(int i=0; i<n; i++)
gets(mp[i]);
cnt=0,tot=0;
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
if(mp[i][j]=='A'||mp[i][j]=='S')
build(i,j),tot++;
kruskal();
}
return 0;
}
POJ3026 Borg Maze 2017-04-21 16:02 50人阅读 评论(0) 收藏的更多相关文章
- linux中的网络通信指令 分类: 学习笔记 linux ubuntu 2015-07-06 16:02 134人阅读 评论(0) 收藏
1.write write命令通信是一对一的通信,即两个人之间的通信,如上图. 效果图 用法:write <用户名> 2.wall wall指令可将信息发送给每位同意接收公众信息的终端机用 ...
- Mahout快速入门教程 分类: B10_计算机基础 2015-03-07 16:20 508人阅读 评论(0) 收藏
Mahout 是一个很强大的数据挖掘工具,是一个分布式机器学习算法的集合,包括:被称为Taste的分布式协同过滤的实现.分类.聚类等.Mahout最大的优点就是基于hadoop实现,把很多以前运行于单 ...
- HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏
Easy Summation Time Limit: 2000/1000 MS ...
- NavBarControl控件 2015-07-23 16:56 2人阅读 评论(0) 收藏
NavBarControl控件 1. 新建一个windows窗体应用程序项目 2. 在工具箱中的Navigation& Layout选项卡下找到NavBarControl, ...
- Hdu 1010 Tempter of the Bone 分类: Translation Mode 2014-08-04 16:11 82人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- iOS开发网络数据之AFNetworking使用 分类: ios技术 2015-04-03 16:35 105人阅读 评论(0) 收藏
http网络库是集XML解析,Json解析,网络图片下载,plist解析,数据流请求操作,上传,下载,缓存等网络众多功能于一身的强大的类库.最新版本支持session,xctool单元测试.网络获取数 ...
- Hdu4135 Co-prime 2017-06-27 16:03 25人阅读 评论(0) 收藏
Co-prime Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Subm ...
- Oracle 字符集的查看和修改 分类: H2_ORACLE 2013-06-19 16:52 316人阅读 评论(0) 收藏
一.什么是Oracle字符集 Oracle字符集是一个字节数据的解释的符号集合,有大小之分,有相互的包容关系.ORACLE 支持国家语言的体系结构允许你使用本地化语言来存储,处理,检索数据.它使数据库 ...
- Copy page via powershell and not save as template 分类: Sharepoint 2015-07-16 16:39 4人阅读 评论(0) 收藏
By save as template informaton of the page get lost, e.g. permissions. To avoid this, use powershell ...
随机推荐
- Spring 中的国际化Message的简单例子(ApplicationContext) 不跟框架集成的版本
首先,建立一个描述message的XML文件,名为messages.xml <?xml version="1.0" encoding="UTF-8" ...
- How to Pronounce T and D between Consonants
How to Pronounce T and D between Consonants Share Tweet Share Tagged With: Dropped T What happens to ...
- Implementing the On Item Checked Event for the TListView Control
The TListView Delphi control displays a list of items in a fashion similar to how Windows Explorer d ...
- ubuntu 安装 selenium selenium操作 chrome
重装虚拟机,好多包需要重装,sele这个记得当时就找了好久的完整重装方法,这次又找了好久,,,省的下次再这样,记录下来..... ubuntu16.04 4安装seleniumsudo pip ins ...
- 使用github的流程
使用github的流程 在实际项目开发中,按照如下步骤使用git进行代码管理 1.项目经理在开发之初,创建好仓库,上传项目的框架.组员分支 2.组员克隆项目框架,同步分支,按分工开发,在分支提交代码 ...
- threading实例
import paramiko, threading import queue import pymysql class ThreadPool(object): def __init__(self, ...
- 进程间通信-Queue
进程间通信-Queue Process之间有时需要通信,操作系统提供了很多机制来实现进程间的通信. 1. Queue的使用 可以使用multiprocessing模块的Queue实现多进程之间的数据传 ...
- jqeury datatable/http://www.cnblogs.com/jobs2/p/3431567.html
0.http://blog.csdn.net/mickey_miki/article/details/8240477 1.1 修改默认值 代码 841处options 添加分页选择 oInit.bL ...
- Fragment 实现拍照,相册选图,设置头像功能
设置不成功,http://bbs.csdn.net/topics/391112964 采纳问题回答:这个是fragment没有收到这个回调,原因不多说了,,,你用你对应的ragment.startAc ...
- mysql数据类型长度
1个字节= 8位 tinyint 为一个字节 2的8次方= 256 所以最多存储到256 日期和时间数据类型 MySQL数据类型 含义 date 3字节,日期,格式:2014-09-18 time ...