坑爹题,两种输入输出互相交换,裸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坑爹题)的更多相关文章

  1. POJ 3984 - 迷宫问题 - [BFS水题]

    题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...

  2. BFS简单题套路_Codevs 1215 迷宫

    BFS 简单题套路 1. 遇到迷宫之类的简单题,有什么行走方向的,先写下面的 声明 ; struct Status { int r, c; Status(, ) : r(r), c(c) {} // ...

  3. 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 ...

  4. URAL 1119. Metro(BFS)

    点我看题目 题意  : 这个人在左下角,地铁在右上角,由很多格子组成的地图,每一条边都是一条路,每一条边都是100米.还有的可以走对角线,问你从起点到终点最短是多少. 思路 : 其实我想说一下,,,, ...

  5. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  6. hdu1240 bfs 水题

    原题链接 思路:水题,直接搜 #include "map" #include "queue" #include "math.h" #incl ...

  7. bfs简单题-poj2251

    宽搜基础题 思路很简单,注意细节. 走过的节点一定要打上标记//tag数组 三维字符串输入一定要注意 #include <stdio.h> #include <iostream> ...

  8. 1008. Image Encoding(bfs)

    1008 没营养的破题 #include <iostream> #include<cstdio> #include<cstring> #include<alg ...

  9. POJ 3278 Catch That Cow(BFS,板子题)

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 88732   Accepted: 27795 ...

随机推荐

  1. Oracle 用户权限管理

    SQL> select * from ROLE_SYS_PRIVS where ROLE='RESOURCE'; ROLE PRIVILEGE ADM --------------------- ...

  2. -_-#Android版QQ浏览器广告过滤

    省流加速 - 广告过滤   默认开启 设别广告是添加的标签最外层标签带有adv download

  3. 调用test case集,并生成测试报告

    结构是 test_all.py 进行配置,执行所有测试用例集,并合并测试报告到同一个文件 #test_all.py 进行配置,执行所有测试用例集 # coding = utf-8 from time ...

  4. HDOJ 1048 The Hardest Problem Ever(加密解密类)

    Problem Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caes ...

  5. mysql binaryVInstall

    下载mysql 1.下载:在http://dev.mysql.com/downloads/mysql/官网上下载mysql-5.5.28-linux2.6-i686.tar.gz. 2.解压 -lin ...

  6. 使用 Docker 容器应该避免的 10 个事情

    当你最后投入容器的怀抱,发现它能解决很多问题,而且还具有众多的优点: 第一:它是不可变的 – 操作系统,库版本,配置,文件夹和应用都是一样的.您可以使用通过相同QA测试的镜像,使产品具有相同的表现. ...

  7. iOS speex

    1. http://www.cocoachina.com/bbs/read.php?tid=114755 2, http://blog.csdn.net/jiangyiaxiu/article/det ...

  8. Struts2学习笔记(一):Struts2开发环境的配置

    一.Struts2应用所需的jar文件. 开发struts2应用需要依赖的jar文件在解压目录下的lib文件夹里面.开发struts2程序最少需要的jar文件为:struts2-core-2.xx.j ...

  9. iOS UITextField 设置内边距

    [self.yourTextField setValue:[NSNumber numberWithInt:5] forKey:@"_paddingTop"]; [self.your ...

  10. SKPhysicsJointSliding类

    继承自 NSObject 符合 NSCoding(SKPhysicsJoint)NSObject(NSObject) 框架  /System/Library/Frameworks/SpriteKit. ...