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 ...
随机推荐
- SqlServer里DateTime转字符串
Select CONVERT(varchar(100), GETDATE(), 8):14:53:14 Select CONVERT(varchar(100), GETDATE(), 9): 06 ...
- LintCode-Unique Path II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- Javascript数据类型之Undefined和null
Javascrip中的数据类型分为原始数据类型(primitive type)和对象数据类型(object type). 原始数据类型 原始数据类型包括:数字.字符串.布尔值.null.undefin ...
- windows server 2008 下安装openmeetings 2.2.0
经过两天的痛苦经历,终于完成了openmeetings的安装部署.其实步骤都很简单,只是网上的资料都是英文的,而且很多教程都是针对openmeeting之前的版本,导致我在部署的时候走了很多弯路.网上 ...
- sublime package
Sublime text 2/3 中 Package Control 的安装与使用方法 2014/05/23前端工具, 工具, 教程, 软件4条评论 Package Control 插件是一个方便 S ...
- C# Socket连接超时设置
问题描述: 对于C# Socket没有超时设置的选项,默认情况下进行Socket连接,返回连接失败需要20-30s时间,严重影响用户体验 问题解决: Socket服务器端: Socke ...
- unity3d旋转摄像机脚本
void Update () { )) { if (axes == RotationAxes.MouseXAndY) { // Read the mouse input axis rotationX ...
- HDU 2544 最短路(模板题)
求1到N的最短路径,模板题,以1为源点,用dijkstra算法(可以用优先级队列优化) #include <iostream> #include <algorithm> #in ...
- Javascript的动态运动(1)
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- CF 86D Powerful array
离线+分块 将n个数分成sqrt(n)块. 对所有询问进行排序,排序标准: 1. Q[i].left /block_size < Q[j].left / block_size (块号 ...