1008. Image Encoding(bfs)
没营养的破题
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<queue>
using namespace std;
typedef struct node
{
int x,y;
}st;
int vis[][],w[][];
int n,o[],dis[][] = {{,},{,},{-,},{,-}};
int s[][],gg;
char ss[][];
st p[];
int judge(int x,int y)
{
if(x<||x>||y<||y>)
return ;
if(!w[x][y])
return ;
return ;
}
char swit(int x)
{
if(x==)
return 'R';
else if(x==)
return 'T';
else if(x==)
return 'L';
else
return 'B';
}
void bfs()
{
int i,g=,j;
queue<st>q;
st te,tt;
q.push(p[]);
vis[p[].x][p[].y] = ;
while(!q.empty())
{
te = q.front();
q.pop();
g++;
for(i = ; i < ; i++)
{
int tx = te.x+dis[i][];
int ty = te.y+dis[i][];
if(judge(tx,ty))
{
if(!vis[tx][ty])
{
o[g]++;
s[g][o[g]] = i;
vis[tx][ty] = ;
tt.x = tx;
tt.y = ty;
q.push(tt);
}
}
}
}
printf("%d %d\n",p[].x,p[].y);
for(i =; i <= n ; i++)
{
for(j = ; j <= o[i] ; j++)
{
printf("%c",swit(s[i][j]));
}
if(i!=n)
printf(",\n");
else
printf(".\n");
}
}
bool cmp(node a,node b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
void bfs1(int x,int y)
{
int i,g=;
queue<st>q;
st te,tt;
te.x = x;
te.y = y;
q.push(te);
vis[x][y] = ;
while(!q.empty())
{
te = q.front();
q.pop();
g++;
p[g].x = te.x;
p[g].y = te.y;
int k = strlen(ss[g]);
for(i = ; i < k ; i++)
{
if(ss[g][i]=='.'||ss[g][i]==',')
break;
int tx,ty;
if(ss[g][i]=='R')
{
tx = te.x+;
ty = te.y;
}
else if(ss[g][i]=='T')
{
tx = te.x;
ty = te.y+;
}
else if(ss[g][i]=='L')
{
tx = te.x-;
ty = te.y;
}
else
{
tx = te.x;
ty = te.y-;
}
if(!vis[tx][ty])
{
vis[tx][ty] = ;
tt.x = tx;
tt.y = ty;
q.push(tt);
}
}
}
sort(p+,p+g+,cmp);
printf("%d\n",g);
for(i = ; i <= g ; i++)
printf("%d %d\n",p[i].x,p[i].y);
}
int main()
{
int i,j;
char c[],c1[],c2[];
gets(c);
int k = strlen(c);
for(i = ; i < k ; i++)
{
c1[i] = c[i];
if(c[i]==' ')
break;
}
c1[i] = '\0';
if(i==k)
{
n = atoi(c);
for(i =; i <= n ;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
w[p[i].x][p[i].y] = ;
}
sort(p+,p+n+,cmp);
bfs();
}
else
{
int oo=;
for(j = i+ ; j < k ; j++)
c2[oo++] = c[j];
c2[oo] ='\0';
int x = atoi(c1);
int y = atoi(c2);
gg=;
while(cin>>ss[gg])
{
if(ss[gg][]=='.')
break;
gg++;
}
bfs1(x,y);
}
return ;
}
1008. Image Encoding(bfs)的更多相关文章
- PAT 甲级 1008 Elevator (20)(代码)
1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...
- URAL 1008 - Image Encoding(bfs坑爹题)
坑爹题,两种输入输出互相交换,裸bfs #include <stdio.h> #include <string.h> typedef struct { int x; int y ...
- 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)
//1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...
- 【BZOJ】1008: [HNOI2008]越狱(组合数学)
题目 题目描述 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱 输入输出格式 ...
- 1008: [HNOI2008]越狱(计数问题)
1008: [HNOI2008]越狱 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 11361 Solved: 4914[Submit][Status ...
- SVN遇到Can't convert string from 'UTF-8' to native encoding(转)
svn: Can't convert string from 'UTF-8' to native encoding: svn: platform/console-framework/portal/im ...
- 1218. Episode N-th: The Jedi Tournament(bfs)
1218 简答题 对于当前点 判断每个点是否可达 #include <iostream> #include<cstdio> #include<cstring> #i ...
- ZOJ 1008 Gnome Tetravex(DFS)
题目链接 题意 : 将n*n个正方形进行排列,需要判断相邻的正方形的相邻三角形上边的数字是不是都相等. 思路 : 只知道是个深搜,一开始不知道怎么搜,后来看了题解才明白,就是说不是自己去搜,而是将给定 ...
- encoding(hdoj1020)
Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following ...
随机推荐
- 动画(Animation) 之 (闪烁、左右摇摆、上下晃动等效果)
左右晃动的效果: (这边显示没那么流畅) 一.续播 (不知道取什么名字好,就是先播放动画A, 接着播放动画B) 有两种方式. 第一种,分别动画两个动画,A和B, 然后先播放动画A,设置A 的 Ani ...
- 在一个Activity里面的TextView上面添加网页链接,启动后到另一个Activity里面!
可以添加很多的属性,样式或者是什么的,目前要完成的功能是 点击TextView里面的某个文字链接,进入另外一个Activity里面!例如你可以做微博里面的 @XXX: 点击后进入他的个人主页! 下面都 ...
- 关于windbg的认识
1.windbg是一个用于调试代码的工具,基础介绍:http://www.pediy.com/kssd/pediy10/94457.html 2.关于windbg和vs在代码调试方面的区别,参考:ht ...
- 给Jquery添加alert,prompt方法,类似系统的Alert,Prompt,可以响应键盘,支持拖动
我们在调用系统的Alert,prompt的弹出提示时,不同的系统会有不同的提示框,视觉效果不统一,而且不好看,功能单一,现在我们通过Jquery模拟Alert,prompt,现实统一视觉效果,而且内容 ...
- Even Fibonacci numbers
--Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting ...
- REST_FRAMEWORK加深记忆-第二次练习官方文档
我想,其它几个基于PYTHON的REST API模块概念都差不多吧. 先深入搞定这个吧. 前几次练习完了有一些印象,并且在工作中实践过一个,现在多弄几次,玩熟悉点. Serializers.py __ ...
- 黑马程序员-- .net基础加强8之委托,事件,程序集
---------------------- ASP.Net+Android+IOS开发..Net培训.期待与您交流! ---------------------- 一.委托 ============ ...
- 找啊找啊找GF
P1013 找啊找啊找GF 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 MM七夕模拟赛 描述 "找啊找啊找GF,找到一个好GF,吃顿饭啊拉拉手, ...
- lintcode:Plus One 加一
题目: 加一 给定一个非负数,表示一个数字数组,在该数的基础上+1,返回一个新的数组. 该数字按照大小进行排列,最大的数在列表的最前面. 样例 给定 [1,2,3] 表示 123, 返回 [1,2,4 ...
- SpringMVC学习总结(三)——Controller接口详解(1)
4.12.ParameterizableViewController 参数化视图控制器,不进行功能处理(即静态视图),根据参数的逻辑视图名直接选择需要展示的视图. <bean name=&quo ...