URAL 1008 - Image Encoding(bfs坑爹题)
坑爹题,两种输入输出互相交换,裸bfs
#include <stdio.h>
#include <string.h>
typedef struct
{
int x;
int y;
} point;
point q[310]; int vis[15][15],mat[15][15];
int dx[4]= {1,0,-1,0};
int dy[4]= {0,1,0,-1};
char ans[5]= {"RTLB"}; int bfs1(int x,int y)
{
int front=0,rear=0;
q[rear].x=x;
q[rear].y=y;
rear++;
while(front<rear)
{
int u=q[front].x;
int v=q[front].y;
for(int i=0; i<4; i++)
{
int xx=u+dx[i];
int yy=v+dy[i];
if(mat[xx][yy]&&!vis[xx][yy]&&xx>0&&xx<=10&&yy>0&&yy<=10)
{
printf("%c",ans[i]);
vis[xx][yy]=1;
q[rear].x=xx;
q[rear].y=yy;
rear++;
}
}
front++;
if(front==rear)
printf(".\n");
else
printf(",\n");
}
}
int bfs2(int x,int y)
{
int front=0,rear=0;
char s[10];
q[rear].x=x;
q[rear].y=y;
rear++;
while(front<rear)
{
int u=q[front].x;
int v=q[front].y;
scanf("%s",s);
for(int i=0;i<strlen(s)-1;i++)
{
for(int j=0;j<4;j++)
if(s[i]==ans[j])
{
int xx=u+dx[j];
int yy=v+dy[j];
mat[xx][yy]=1;
q[rear].x=xx;
q[rear].y=yy;
rear++;
}
}
front++;
}
int ct=0;
for(int i=1;i<=10;i++)
{
for(int j=1;j<=10;j++)
if(mat[i][j])ct++;
}
printf("%d\n",ct);
for(int i=1;i<=10;i++)
{
for(int j=1;j<=10;j++)
if(mat[i][j])
printf("%d %d\n",i,j);
}
}
int main()
{
int n,x,y,k;
memset(mat,0,sizeof(mat));
memset(vis,0,sizeof(vis));
while(scanf("%d",&n)==1)
{
int a;
if(getchar()=='\n')
{
while(n--)
{
scanf("%d%d",&x,&y);
mat[x][y]=1;
}
for(int i=1; i<=10; i++)
{
for(int j=1; j<=10; j++)
{
if(mat[i][j]&&!vis[i][j])
{
vis[i][j]=1;
printf("%d %d\n",i,j);
bfs1(i,j);
}
}
}
}
else
{
scanf("%d",&k);
mat[n][k]=1;
bfs2(n,k);
} } return 0;
}
URAL 1008 - Image Encoding(bfs坑爹题)的更多相关文章
- POJ 3984 - 迷宫问题 - [BFS水题]
题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...
- BFS简单题套路_Codevs 1215 迷宫
BFS 简单题套路 1. 遇到迷宫之类的简单题,有什么行走方向的,先写下面的 声明 ; struct Status { int r, c; Status(, ) : r(r), c(c) {} // ...
- POJ-2251 Dungeon Master (BFS模板题)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- URAL 1119. Metro(BFS)
点我看题目 题意 : 这个人在左下角,地铁在右上角,由很多格子组成的地图,每一条边都是一条路,每一条边都是100米.还有的可以走对角线,问你从起点到终点最短是多少. 思路 : 其实我想说一下,,,, ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- hdu1240 bfs 水题
原题链接 思路:水题,直接搜 #include "map" #include "queue" #include "math.h" #incl ...
- bfs简单题-poj2251
宽搜基础题 思路很简单,注意细节. 走过的节点一定要打上标记//tag数组 三维字符串输入一定要注意 #include <stdio.h> #include <iostream> ...
- 1008. Image Encoding(bfs)
1008 没营养的破题 #include <iostream> #include<cstdio> #include<cstring> #include<alg ...
- POJ 3278 Catch That Cow(BFS,板子题)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 88732 Accepted: 27795 ...
随机推荐
- 关于extern "C" 的用法
而在C语言的头文件中,对其外部函数只能指定为extern类型,C语言中不支持extern "C"声明,在.c文件中包含了extern "C"时会出现编译语法错误 ...
- [Android] 输入系统(一)
Android输入系统是人与机器交互最主要的手段.我们通过按键或者触碰屏幕,会先经由linux产生中断,进行统一的处理过后,转换成Android能识别的事件信息,然后Android的输入系统去获取事件 ...
- BZOJ1708: [Usaco2007 Oct]Money奶牛的硬币
1708: [Usaco2007 Oct]Money奶牛的硬币 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 513 Solved: 329[Submi ...
- 使用read(),write(),seekg(),seekp()实现二进制方式文件随机存取
// binary.cpp -- binary file I/O #include <iostream> #include <fstream> #include <iom ...
- [Linux] 流 ( Stream )、管道 ( Pipeline ) 、Filter - 笔记
流 ( Stream ) 1. 流,是指可使用的数据元素一个序列. 2. 流,可以想象为是传送带上等待加工处理的物品,也可以想象为工厂流水线上的物品. 3. 流,可以是无限的数据. 4. 有一种功能, ...
- xshell中启动linux图形界面
使用root用户执行xhost + IP为客户端机器IP,使用远程登录用户执行 DISPLAY=IP:0.0;export DISPLAY; 使用远程登录的用户执行: xhost +
- HDU1257:最少拦截系统(LIS)
Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高 ...
- Android控件Editext、TextView属性详解
EditText属性描述 android:layout_gravity="center_vertical"//设置控件显示的位置:默认top,这里居中显示,还有bottom and ...
- 网络编程TCP总结及实践-C语言
网络变成首先要注意IP和port的转换,如今电脑基本上是主机字节序,存储依照小端方式,而在网络中传输统一使用大端方式,所以网络变成首先要注意字节序的转换. 一个经常使用的ip转换程序的实现: #inc ...
- [MongoDB] Introduce to MongoDB
1. Use or create a database: use wandRecorder You will use keyword to create or fetch a exicting dat ...