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 ...
随机推荐
- Javascript 获取dom的宽度 随笔一
javascript 中 offsetWidth 获得的并不是 真实的宽度 不等于 style.width ;offetWidth 实际上获得的是物体的盒模型尺寸. 包括 border padding ...
- jQuery插件infinitescroll参数【无限翻页】
转自:http://blog.163.com/penglie_520/blog/static/19440505020127255319862/ infinite-scroll-jquery 参数详解: ...
- pojPots
http://poj.org/problem?id=3414 #include<cstdio> #include<cstring> #define MAXN 1000000 u ...
- Eclipse里的智能提示
Eclipse 3.1里的智能提示功能对于写JAVA程序又不记得类名和函数的人来说是一个很好的助手工具,但是Eclipse里的智能提示的快捷键是Ctrl+Space,在中文Windows操作系统中它确 ...
- 感兴趣的Linux发行版
1. Ubuntu,包括KUbuntu,XUbuntu,Kyrin等等 2. BluestarLinux - 基于Arch Linux,感觉很美 http://sourceforge.net/proj ...
- POJ3267 The Cow Lexicon(dp)
题目链接. 分析: dp[i]表示母串从第i位起始的后缀所对应的最少去掉字母数. dp[i] = min(dp[i+res]+res-strlen(pa[j])); 其中res 为从第 i 位开始匹配 ...
- BZOJ 1020 [SHOI2008]安全的航线flight
1020: [SHOI2008]安全的航线flight Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 847 Solved: 286[Submit][ ...
- HDOJ 2072 单词数
Problem Description lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数.下面你的任务是帮助xiaoou333解决这个问题. ...
- UVAlive3523 Knights of the Round Table(bcc)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18122 [思路] 点-双连通分量 求出bcc,判断每个bcc是否为 ...
- webex录屏
你在寻找好用的录屏软件吗?商用级品质的 WebEx Recorder 就是一款优秀的录屏软件.WebEx Recorder可以录制全屏或指定窗口,可以设定是否包含声音,生成的文件体积极小且极清晰,录制 ...