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 ...
随机推荐
- 分析 "ADO" "ADODB" "ADODC" 之间的区别与联系
在敲学生信息管理系统的时候,通过查阅了解了一些关于 ADO / ADODB / ADODC / 的简单描述,想想将他们对 比着总结一下更容易理解记忆.尽管都是一些浅显的东西,不过对像我这样的菜鸟们还是 ...
- Daily Scrum 11.11
摘要:本次会议继续讨论程序的问题以及单元测试和集成测试,本次测试为1.02版本.本次的Task列表如下: Task列表 出席人员 Today's Task Tomorrow's Task 刘昊岩 t ...
- <a href='?out=login'>是什么意思
<a href='?out=login'>退出</a>前面加上问号?就是GET方式传递out=login是要传递的数据点这个链接就可以执行 接下来通过$_GET["o ...
- asp.net 中给gridview添加自动序号
第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. 代码如下: <asp:TemplateField HeaderText="序号&quo ...
- 1934: [Shoi2007]Vote 善意的投票 - BZOJ
Description幼儿园里有n个小朋友打算通过投票来决定睡不睡午觉.对他们来说,这个问题并不是很重要,于是他们决定发扬谦让精神.虽然每个人都有自己的主见,但是为了照顾一下自己朋友的想法,他们也可以 ...
- php 安全处理方案
Safe::mysqlSafe(); sql注入,升级5.3.6以上版本php 方案一:将所有请求中所有数据(get/post/cookie)实现mysql_escape_string进行安全处理. ...
- mac mysql安装
一.安装 1.下载软件包直接安装即可: http://rj.baidu.com/soft/detail/25675.html?ald 安装完成后root默认密码为空: 二.修改密码 直接修改密码会提示 ...
- 基于AgileEAS.NET企业应用开发平台的分布式解决方案
开篇 分布式应用 AgileEAS.NET基于Microsoft .Net构件技术而构建,Microsoft .Net最吸引人的莫过于分布式应用技术,基已经提供了XML WebService. .Ne ...
- Eclipse插件开发 swt ComboBoxCellEditor CCombo 下拉框高度
效果图: 代码如下 bindingPageTableViewer.setCellModifier(new ICellModifier() { public boolean canModify( ...
- [C/CPP系列知识] C++中extern “C” name mangling -- Name Mangling and extern “C” in C++
http://www.geeksforgeeks.org/extern-c-in-c/ C++函数重载(function overloading),但是C++编译器是如何区分不同的函数的呢?----是 ...