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 ...
随机推荐
- 微软职位内部推荐-Sr. Dev Lead
微软近期Open的职位: JD 如果你想试试这个职位,请跟我联系,我是微软的员工,可以做内部推荐.发你的中英文简历到我的邮箱:Nicholas.lu.mail(at)gmail.com
- git check 分支代码
1.git clone xxx.git; 2.git branch -r //查看分支 3.git checkout origin/分支名字 -b 本地新建分支名字 //从远程分支名字 down代码 ...
- Javascript 面向对象编程
Javascript是一个类C的语言,他的面向对象的东西相对于C++/Java比较奇怪,但是其的确相当的强大,在 Todd 同学的“对象的消息模型”一文中我们已经可以看到一些端倪了.这两天有个前同事总 ...
- aes 解密出现 java.lang.NumberFormatException: Invalid int: "ch"
原因: 将加密/解密的seed 和 加密内容顺序放反. decrypt(String seed, String encrypted) 附上AES解密/加密代码(android开发): package ...
- Luence简单实现1
初步认识Luence,简单按照官方文档做了个例子,大牛绕开,仅供小白路过参考.如有错误,欢迎指正批评. 建一个简单工程,并且加入这几个小奶瓶,如下图: 注:版本不同,可能对jdk的需求是不同的,这个需 ...
- hadoop历史服务器配置问题
作者:sdjnzqr 出处:http://www.cnblogs.com/sdjnzqr/ 版权:本文版权归作者和博客园共有 转载:欢迎转载,但未经作者同意,必须保留此段声明:必须在文章中给出原文连接 ...
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
The Himalayas http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5341 签到 #include<cstdio& ...
- uva 10900
题意一直没看懂~~~~不过看懂了之后还是感觉挺好的 #include<cstdio> #include<cstring> #include<algorithm> # ...
- python中精确输出JSON浮点数的方法
有时需要在JSON中使用浮点数,比如价格.坐标等信息.但python中的浮点数相当不准确, 例如下面的代码: 复制代码代码如下: #!/usr/bin/env python import json a ...
- Linux性能监控分析命令
vmstat sar iostat top free uptime netstat ps strace lsof