题目链接

 Problem 1688 Binary land

Accept: 72    Submit: 171
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

Daxia liked a game named “binary land” (双企鹅,一款家机游戏) when he was a child. Now, we will solve the problem about this game.You are in control of two penguins – Gurin (blue) and Malon (pink). Each level is divided more or less in half, with Gurin on the right and Malon on the left. They move the same way in vertical direction, but they move in a mirror image in horizontal direction. That is if you press right, Gurin moves right but Malon moves left, and if you press left, Gurin moves left but Malon moves right. You can press up, down, left and right. If an operation leads the penguin to the wall, the penguin will stay in the original place. Every operation is counted one step.

These two penguins are in love and so your task is to open the cage with the heart on the top of the screen. This cage can be opened only if the penguins are on both sides of it as the following picture (either Gurin on the right or on the left is OK). Now ask you to compute the least steps to achieve it.

 Input

Input contains several cases. Each case includes ten lines, each line has fifteen characters. The eighth column is always beginning with one cage with the heart and following nine walls. The wall can't be across but the cage with the heart can be across. The two penguins can be across each other, too. There is a blank line between two cases. The meaning of the characters is:

  • "." is used for road.
  • "#" is used for wall.
  • "G" is used for Gurin (only one, and in the tenth line and ninth column).
  • "M" is used for Malon (only one, and in the tenth line and seventh column).
  • "C" is used for cage with the heart (only one, and in the first line and eighth column).

 Output

Ououtput a single line for each of the case. This line should contain either "Case i: d" or "Case i: They can’t break open the cage!", where i is the case number (counting from 1) and d is the minimum steps needed to use.

 Sample Input

.......C.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
......M#G...... .......C.......
.###.###.###.##
##.#.#.###.#.#.
.......#.......
.#####.#.#####.
.......#.......
##.#.#.#.#.#.##
.......#.......
.#############.
......M#G...... ......#C.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
......M#G......

 Sample Output

Case 1: 9
Case 2: 30
Case 3: They can't break open the cage!
 
分析 
  裸的bfs问题。同时处理两个点的行走就好。比赛时想到了但没有去码,后悔莫及啊,太年轻。
 
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn = 1e4+;
const int mod = +;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a)) int d[][][][];
char g[][];
pii C,G,M;
queue<pair<pii,pii> > q;
int dx[]={,,-,};
int dy[]={,,,-};
const int inf = 0x3f3f3f3f;
int main(){
//cout<<inf;
int cas=;
while(~scanf("%s",g[])){
for(int i=;i<;i++) scanf("%s",g[i]);
for(int i=;i<;i++){
for(int j=;j<;j++){
if(g[i][j]=='C') C=mp(i,j);
else if(g[i][j]=='G') G=mp(i,j);
else if(g[i][j]=='M') M=mp(i,j);
}
}
// for(int i=0;i<10;i++) puts(g[i]); ms(d,inf);
d[G.X][G.Y][M.X][M.Y]=;
q.push(mp(G,M));
while(!q.empty()){
pii tg=q.front().X;
pii tm=q.front().Y;
q.pop();
for(int i=;i<;i++){
pii a=tg,b=tm;
a.X+=dx[i]; a.Y+=dy[i];
b.X+=dx[i]; b.Y-=dy[i];
if(a.X<||a.X>||a.Y<||a.Y>) a=tg;
if(b.X<||b.X>||b.Y<||b.Y>) b=tm;
if(g[a.X][a.Y]=='#') a=tg;
if(g[b.X][b.Y]=='#') b=tm;
if(d[a.X][a.Y][b.X][b.Y]!=inf) continue;
d[a.X][a.Y][b.X][b.Y]= d[tg.X][tg.Y][tm.X][tm.Y]+;
q.push(mp(a,b));
}
}
// int ans=min(d[C.X][C.Y+1][C.X][C.Y-1],d[C.X][C.Y-1][C.X][C.Y+1]);
int ans=d[C.X][C.Y+][C.X][C.Y-];
printf("Case %d: ",cas++);
if(ans==inf){
puts("They can't break open the cage!");
}else cout<<ans<<endl;
} return ;
}
 

FZU - 1688 Binary land的更多相关文章

  1. Luogu3855 [TJOI2008]Binary Land (BFS)

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...

  2. 畅通工程再续(MST)

    畅通工程再续 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  3. FC红白机游戏列表(维基百科)

    1055个fc游戏列表 日文名 中文译名 英文版名 发行日期 发行商 ドンキーコング 大金刚 Donkey Kong 1983年7月15日 任天堂 ドンキーコングJR. 大金刚Jr. Donkey K ...

  4. Codechef May Challenge 2020 Division 1 记录

    目录 Triple Sort Sorting Vases Buying a New String Chef and Bitwise Product Binary Land Not a Real Wor ...

  5. hdu----(5050)Divided Land(二进制求最大公约数)

    Divided Land Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  6. HDU 5050 Divided Land(进制转换)

    题意  给你两个二进制数m,n   求他们的最大公约数  用二进制表示  0<m,n<2^1000 先把二进制转换为十进制  求出最大公约数  再把结果转换为二进制  数比較大要用到大数 ...

  7. [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法

    二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...

  8. ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id

    出现场景:当点击"分类"再返回"首页"时,发生error退出   BUG描述:Caused by: java.lang.IllegalArgumentExcep ...

  9. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

随机推荐

  1. Oracle 通过触发器实现ID自增

    Oracle不像Mysql,SQLServer能够直接设置ID自增,但是可以通过触发器实现ID自增. 1 创建测试表 create table t_goods(id number primary ke ...

  2. Linux 忘记root密码

    1 将系统重启,读秒的时候按下任意键就会出现如下图菜单界面 2 进入上图菜单界面之后,按e键就可以进入grub的编辑模式 3 选择第二行 kernel开头,再按 e 键进入该行的编辑界面中,然后在出现 ...

  3. [转帖]看完这篇文章你还敢说你懂JVM吗?

    看完这篇文章你还敢说你懂JVM吗? 在一些物理内存为8g的服务器上,主要运行一个Java服务,系统内存分配如下:Java服务的JVM堆大小设置为6g,一个监控进程占用大约 600m,Linux自身使用 ...

  4. C++的内存分区

    C++的内存划分为栈区.堆区.全局区/静态区.字符串常量和代码区. 栈区 由系统进行内存的管理. 主要存放函数的参数以及局部变量.在函数完成执行,系统自行释放栈区内存,不需要用户管理.整个程序的栈区的 ...

  5. 深入理解 Laravel 中 config 配置加载原理

    Laravel的配置加载其实就是加载config目录下所有文件配置.如何过使用php artisan config:cache则会把加载的配置合并到一个配置文件中,下次请求就不会再去加载config目 ...

  6. CENTOS7修改ip

    编辑网卡设置 vi /etc/sysconfig/network-scripts/ifcfg-ens33 编辑内容 vi /etc/sysconfig/network-scripts/ificg-en ...

  7. Java之使用HttpClient发送GET请求

    package LoadRunner; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import o ...

  8. BZOJ2004 HNOI2010公交线路(状压dp+矩阵快速幂)

    由数据范围容易想到矩阵快速幂和状压. 显然若要满足一辆公交车的相邻站台差不超过p,则每相邻p个站台中每辆车至少经过一个站台.可以发现这既是必要的,也是充分的. 开始的时候所有车是相邻的.考虑每次把一辆 ...

  9. AJAX--总结

    AJAX 2018-9-6 14:42:53 AJAX简介 ​ HTTP协议------>HTTP权威指南 ​ 请求:客户端去向服务端请求一个文件 ​ 响应:服务端把对应的文件内容返回给客户端, ...

  10. poj 2236 Wireless Network (并查集)

    链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...