题目链接

 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. JavaScript封装方法,兼容参数类型为Number和String

    /** * 依据Kind确定跳转到目标列表页面. * @param kind */ function gobackByKind(kind) { var kindStr = String(kind); ...

  2. [cnbeta]iPhone 2018年全球出货2.25亿部:中国区下滑两成

    iPhone 2018年全球出货2.25亿部:中国区下滑两成 2019年01月22日 20:12 501 次阅读 稿源:快科技 0 条评论   https://www.cnbeta.com/artic ...

  3. Oracle重新获取统计信息以及SQLSERVER重建索引

    Oracle重新获取统计信息 exec dbms_stats.gather_schema_stats(ownname =>'LCoe739999',options => 'GATHER', ...

  4. 关于mybatis的@Param注解和参数

    1,使用@Param注解 当以下面的方式进行写SQL语句时: @Select("select column from table where userid = #{userid} " ...

  5. Python 零基础 快速入门 趣味教程 (咪博士 海龟绘图 turtle) 7. 条件循环

    条件循环能够让程序在条件成立时(即为真时)重复执行循环体中的语句.如果条件一直成立(即永远不会为假),则循环会一直进行下去,不会停止.如果初始时,条件不成立,则循环 1 次也不会执行.Python 中 ...

  6. Lodop多分出空白页的可能(情况1)

    在用Lodop进行打印超文本的时候,本身内容看上去只有一页,却分页分出空白的一页,很有可能有不可见内容的存在,下面是测试的一种情况,如html内部有内容占着空间,却是不可见的,如一些对象,或者如测试内 ...

  7. IT行业­——Linux

    现在是21世纪,是科学技术大力发展的一个时代,IT行业已经成为现在的一个非常热门的一个行业,许许多多的人都想要往IT方面发展,找IT方面相关的一个工作.因此,现在也出现了很多IT培训机构,比如培训Li ...

  8. POJ2492-A Bug's Life-并查集扩展应用

    维护一个relation数组,保留着此元素和根元素之间的性别关系.之后就可以判断gay了. #include <cstdio> #include <algorithm> #in ...

  9. MT【72】一个不等式

    证明: 评: 可以思考$\frac{1}{(1+b)^2}+\frac{1}{(1+a)^2}$与$\frac{2}{(1+\sqrt{ab})^2}$大小.

  10. 洛谷P2480 [SDOI2010]古代猪文(费马小定理,卢卡斯定理,中国剩余定理,线性筛)

    洛谷题目传送门 蒟蒻惊叹于一道小小的数论题竟能涉及这么多知识点!不过,掌握了这些知识点,拿下这道题也并非难事. 题意一行就能写下来: 给定\(N,G\),求\(G^{\sum \limits _{d| ...