博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ1130 Alien Security
阅读量:6912 次
发布时间:2019-06-27

本文共 4566 字,大约阅读时间需要 15 分钟。

                                                                                        Alien Security
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 2359   Accepted: 894

Description

You are in charge of security at a top-secret government research facility. Recently your government has captured a live extra-terrestrial (ET) life form, and is hosting an open day for fellow researchers. Of course, not all the guests can be trusted, so they are assigned different security clearance levels. Only guests with a level 5 rating will be allowed into the lab where the extra-terrestrial is being held; other than that, everyone is free to roam throughout the rest of the facility. Each room in the facility is connected via one-way airlocks, so that you can pass through the door in only one direction.
To protect your precious ET you will put in place enhanced security measures (in the form of armed guards) on the route leading to the room containing the ET, but not in the room itself ?the guards do not have sufficient clearance to enter the room containing the ET.
The guards will check the identity and the security rating of all guests trying to pass through the room in which they are stationed, so you would like to place the guards where they will cause the minimum amount of irritation to the guests who have no intention of visiting the ET. The room where the guards must be placed thus satisfies the following two conditions:
1. In order to get to the room containing the ET, the guests must pass through the room containing the guards;
2. There is no other room with this property that is closer to the room containing the ET ?remember, the guards cannot be placed in the room containing the ET itself.
The diagram below illustrates one possible map of your facility:
Note that placing the guards in room 2 would satisfy the first condition, but room 3 is closer to the ET, so the guards must be placed in room 3.

Input

All guests enter through room 0, the entrance to your facility. Your program accepts a sequence of lines containing integers. The first line consists of two integers: the number of rooms, and the room in which the ET is being held (out of his own free will, of course).
The rest of the input is a sequence of lines consisting of only two integers, specifying where the airlock-doors are located. The first number on these lines specifies the source room, and the second the destination room. Remember: you can pass only from the source room to the destination room.

Output

The output of your program consists only of a single line:
Put guards in room N.
where N is the room you've decided to place the guards.

Sample Input

9 40 22 33 45 35 43 66 56 76 84 70 11 77 0

Sample Output

Put guards in room 3.

Source

 
思路:输入的第一行给出点的总数N和所要到达的目标点。各个点的编号从0~N-1。点0是开始点。题目所求为:从点0开始到目标点,找出必须要经过的且离目标点最近的点,输出该点的编号。
        首先从点0开始使用BFS搜索,直到目标点,结束。搜索的过程中记录下从点0到目标点的路径。路径记录的方式为记录点X的前驱点。如:PREV[X]=Y;Y为X的前驱结点。那些必须经过的点一定在这个求出的路径上面。然后从目标点到开始点,一个一个查找,看哪个点符合要求。方法为:将点T设置为已经访问,即VIS[T]=1,然后从开始点0搜索,看是否能够到达目标点。如果能够则这个点就是所求。否则看这个点的前驱结点。一直循环下去,知道开始点。
 
 
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 11 12 #define MAXINT 99999999 13 14 15 using namespace std; 16 17 18 //int data[1000][1000]; 19 20 int prev[300]; 21 int vis[300]; 22 //int path[1000]; 23 24 int countn=0; 25 vector
vt[300]; 26 27 int bfs(int n,int et) 28 { 29 int i; 30 31 queue
q; 32 for(i=0;i
::iterator it; 55 for(it=vt[tmp].begin();it!=vt[tmp].end();it++) 56 { if(vis[*it]==0) 57 {vis[*it]=1; 58 q.push(*it); 59 prev[*it]=tmp; 60 if(*it==et) 61 break; 62 } 63 } 64 } 65 66 67 68 69 return 0; 70 } 71 72 73 74 75 76 77 78 79 int bfs2(int beginv,int n,int et) 80 { 81 int i; 82 83 84 queue
q; 85 86 q.push(beginv); 87 vis[beginv]=1; 88 89 90 while(q.size()) 91 { 92 int tmp=q.front(); 93 q.pop(); 94 95 96 /*for(i=0;i
::iterator it;107 for(it=vt[tmp].begin();it!=vt[tmp].end();it++)108 { if(vis[*it]==0)109 {vis[*it]=1;110 q.push(*it);111 if(*it==et)112 return 1;113 }114 }115 }116 return 0;117 }118 119 120 121 int dfs(int beginv,int n,int et)122 {123 if(beginv==et)124 return 1;125 126 vis[beginv]=1;127 128 vector
::iterator it;129 for(it=vt[beginv].begin();it!=vt[beginv].end();it++)130 { if(vis[*it]==0)131 { if(dfs(*it,n,et))132 return 1;133 }134 }135 136 return 0;137 }138 139 140 141 142 143 144 145 146 int main(int argc, char *argv[])147 {148 int n,et;149 scanf("%d%d",&n,&et);150 int a,b;151 int i,j,k;152 /*for(i=0;i
-1)172 {173 for(i=0;i

 

转载于:https://www.cnblogs.com/zjushuiping/archive/2012/08/01/2619073.html

你可能感兴趣的文章
Data De-duplication
查看>>
虚方法的调用是怎么实现的(单继承VS多继承)
查看>>
PHP 中变量的间接引用
查看>>
对《SQL Server中tempdb的management》的一些更正和补充
查看>>
自适应网页设计(Responsive Web Design)
查看>>
【转】MFC 迅雷七窗体特效,使用DWM实现Aero Glass效果
查看>>
JS查找孩子节点
查看>>
Rhythmk 一步一步学 JAVA (20) JAVA enum常用方法
查看>>
poj3342Party at Hali-Bula(树形dp)
查看>>
Uni2D 入门 -- Animation Clip 和 Animation API
查看>>
C#中的Dictionary类,默认key是区分大小写的
查看>>
win8开机密码忘了怎么办
查看>>
问题集合
查看>>
TP 接收post请求使用框架自带函数I()防止注入
查看>>
WCF学习总结
查看>>
Android Studio项目转Eclipse项目
查看>>
CSM认证培训知识汇总
查看>>
Atitit. 。Jna技术与 解决 java.lang.Error: Invalid memory access
查看>>
zookeeper 安装和配置
查看>>
[转载] 武汉海达数云技术有限公司 - 软件研发员工资详情(武汉,2015年)
查看>>