FZU - 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
- "." 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
Sample Input
.......C.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
......M#G...... .......C.......
.###.###.###.##
##.#.#.###.#.#.
.......#.......
.#####.#.#####.
.......#.......
##.#.#.#.#.#.##
.......#.......
.#############.
......M#G...... ......#C.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
......M#G......
Sample Output
#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的更多相关文章
- Luogu3855 [TJOI2008]Binary Land (BFS)
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...
- 畅通工程再续(MST)
畅通工程再续 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- FC红白机游戏列表(维基百科)
1055个fc游戏列表 日文名 中文译名 英文版名 发行日期 发行商 ドンキーコング 大金刚 Donkey Kong 1983年7月15日 任天堂 ドンキーコングJR. 大金刚Jr. Donkey K ...
- Codechef May Challenge 2020 Division 1 记录
目录 Triple Sort Sorting Vases Buying a New String Chef and Bitwise Product Binary Land Not a Real Wor ...
- hdu----(5050)Divided Land(二进制求最大公约数)
Divided Land Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- HDU 5050 Divided Land(进制转换)
题意 给你两个二进制数m,n 求他们的最大公约数 用二进制表示 0<m,n<2^1000 先把二进制转换为十进制 求出最大公约数 再把结果转换为二进制 数比較大要用到大数 ...
- [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法
二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...
- ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id
出现场景:当点击"分类"再返回"首页"时,发生error退出 BUG描述:Caused by: java.lang.IllegalArgumentExcep ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
随机推荐
- C++拷贝构造函数的调用时机
一.拷贝构造函数调用的时机 当以拷贝的方式初始化对象时会调用拷贝构造函数,这里需要注意两个关键点,分别是以拷贝的方式和初始化对象 1. 初始化对象 初始化对象是指,为对象分配内存后第一次向内存中填 ...
- 测试 多线程 实现 callable 带返回值
package threadTest; import java.util.ArrayList; import java.util.Date; import java.util.concurrent.C ...
- 通过几个例子看sed的模式空间与保持空间
SED之所以能以行为单位的编辑或修改文本,其原因在于它使用了两个空间:一个是活动的“模式空间(pattern space)”,另一个是起辅助作用的“暂存缓冲区(holdingspace)这2个空间的使 ...
- Maven- 自动导入包的方法-很多没有导入的类,如何处理
(1) 比如在pom.xml文件里面引入了类,但是在java中使用这个类的时候,还是报错,那就点击Maven.projects的 左上角的刷新的按钮: (2) 在Maven项目的时候,发现很多的类没有 ...
- Java之枚举类范例
代码如下: package catf.component.http.model; /** * @Auther:gongxingrui * @Date:2018-04-17 * @Description ...
- Markdown 文件转化为work文档
1. 电脑安装pandoc 链接:https://pan.baidu.com/s/12H5wLO0JWph5TjrbeJI6mg 密码:ssgs 下载安装包解压即可用.记得配置系统环境变量 2.命令行 ...
- GO系列教程
1.介绍与安装 2.Hello World 3.变量 4. 类型 5.常量 6.函数(Function) 7.包 8.if-else 语句 9.循环 10.switch语句 11.数组和切片 12.可 ...
- 【转】在单片机中,C语言的一些误用和总结!
在学习单片机的时候才真正知道C语言是什么,它是来干什么的~但是C语言用到嵌入式只是它小小的一部分应用,还有很多地方呢. 我们是不是在写程序的时候,错误很多就算编译通过了也达不到我们预期的结果,完了自己 ...
- luogu1965 转圈游戏 (快速幂)
求(m*10^k+x)%n即可 #include<cstdio> #include<cstring> #include<algorithm> #define LL ...
- 【洛谷P3600】 随机数生成器
https://www.luogu.org/problem/show?pid=3600#sub (题目链接) 题意 一个$n$个数的序列,里面每个数值域为$[1,X]$.给$q$个区间,每个区间的权值 ...