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 ...
随机推荐
- Android 4.0 新增的显示数据集的桌面控件
setRemoteAdapter (int viewId, Intent intent):该方法可以使用 Intent 更新 RemoteViews 中viewId 对应的组件. 上面方法的 Inte ...
- tree .git
$ tree .git .git ├── branches ├── config ├── description ├── FETCH_HEAD ├── gitk.cache ├── HEAD ├── ...
- POJ Wormholes 3259
题目描述: Farmer John 在探索农场的时候 惊奇的发现一些虫洞,虫洞是一个特殊的东西,他是一个单向通道,他能到达虫洞的另一端, 可以穿越到达之前的时间.Farmer John 的由N个农场组 ...
- 【二分】Codeforces 706B Interesting drink
题目链接: http://codeforces.com/problemset/problem/706/B 题目大意: n (1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m ...
- 转自http://blog.sina.com.cn/daylive——C++ STL map
Map是c++的一个标准容器,她提供了很好一对一的关系,在一些程序中建立一个map可以起到事半功倍的效果,总结了一些map基本简单实用的操作! 1.map最基本的构造函数: map<string ...
- 《Linear Algebra and Its Applications》-chaper2-矩阵代数中的基本性质
之前我们曾经提及,完成了线性方程组-向量方程-矩阵方程的等价转化之后,我们对于现实问题中的线性方程组,只需将其转移到矩阵(向量)方程,然后利用矩阵代数中的各种方法和性质进行计算或者化简即可,而下面我们 ...
- 基于deb包快速搭建内外apt源
- java在windows下加载dll
java在类中加载动态链接库文件. 类文件中: static { System.loadLibrary("dll文件"); } dll文件在工程的包路径下.例如:pro/bin/h ...
- Git Push 不用再次输入用户名和密码方法
前言 在大家使用github的过程中,一定会碰到这样一种情况,就是每次要push 和pull时总是要输入github的账号和密码,这样不仅浪费了大量的时间且降低了工作效率.在此背景下,本文在网上找了两 ...
- 2016 cocoapods的安装和使用以及版本升级遇到的问题
一.CocoaPods是什么? CocoaPods是一个负责管理iOS项目中第三方开源库的工具.CocoaPods的项目源码在Github上管理.该项目开始于2011年8月12日,在这两年多的时间里, ...