URAL 1008 Image encoding [BFS]
来源:互联网 发布:阿里手机云空间 编辑:程序博客网 时间:2024/04/29 09:01
题意:两种图像的打印
思路:BFS两种互换
#include <queue>#include <stdio.h>#include <iostream>#include <string.h>using namespace std;typedef struct Point{ int x,y;}point;int xx,yy;bool map[12][12]={0};bool out[12][12]={0};bool did[12][12]={0};void input(int n){ xx=12,yy=12; int x,y; for(int i=0;i<n;i++){ cin>>x>>y; map[x][y]=1; if(x<xx) xx=x,yy=y; else if(x==xx&&y<yy) yy=y; }}void bfs(int n){ queue<point> q; point t; t.x=xx; t.y=yy; cout<<xx<<' '<<yy<<endl; q.push(t); int x,y; int count=0; out[xx][yy]=1; while(q.size()){ t=q.front(); q.pop(); x=t.x; y=t.y; if(did[x][y]) continue; did[x][y]=1; if(map[x+1][y]&&!did[x+1][y]){ if(!out[x+1][y]){ cout<<'R'; out[x+1][y]=1; t.x=x+1; t.y=y; q.push(t); } } if(map[x][y+1]&&!did[x][y+1]){ if(!out[x][y+1]){ cout<<'T'; out[x][y+1]=1; t.x=x; t.y=y+1; q.push(t); } } if(map[x-1][y]&&!did[x-1][y]){ if(!out[x-1][y]){ cout<<'L'; out[x-1][y]=1; t.x=x-1; t.y=y; q.push(t); } } if(map[x][y-1]&&!did[x][y-1]){ if(!out[x][y-1]){ cout<<'B'; out[x][y-1]=1; t.x=x; t.y=y-1; q.push(t); } } count++; if(count!=n) cout<<','<<endl; else cout <<'.'<<endl; }}void bfs(int n,int m){ queue<point> q; point t; t.x=n; t.y=m; map[n][m]=1; q.push(t); char s[5]; int x,y; while(q.size()){ t=q.front(); q.pop(); x=t.x; y=t.y; if(did[x][y]) continue; did[x][y]=1; cin>>s; for(int i=0;i<strlen(s)-1;i++){ if(s[i]=='R'){ map[x+1][y]=1; if(!did[x+1][y]){ t.x=x+1; t.y=y; q.push(t); } } else if(s[i]=='T'){ map[x][y+1]=1; if(!did[x][y+1]){ t.x=x; t.y=y+1; q.push(t); } } else if(s[i]=='L'){ map[x-1][y]=1; if(!did[x-1][y]){ t.x=x-1; t.y=y; q.push(t); } } else if(s[i]=='B'){ map[x][y-1]=1; if(!did[x][y-1]){ t.x=x; t.y=y-1; q.push(t); } } } if(s[strlen(s)-1]=='.') break; } int count=0; for(int i=1;i<=10;i++) for(int j=1;j<=10;j++) if(map[i][j]) count++; cout<<count<<endl; for(int i=1;i<=10;i++) for(int j=1;j<=10;j++) if(map[i][j]) cout<<i<<' '<<j<<endl;}int main(){ int n; cin>>n; if(getchar()=='\n'){ input(n); bfs(n); } else{ int m; cin>>m; bfs(n,m); } return 0;}/*测试:Sample Input62 32 43 33 44 24 3Sample Output2 3RT,RT,,B,,.*/
- URAL 1008 Image encoding [BFS]
- ural 1008 Image Encoding bfs
- URAL 1008 Image Encoding (BFS)
- URAL 1008 - Image Encoding(bfs坑爹题)
- ural 1008. Image Encoding bfs
- ural 1008 Image Encoding
- ural 1008 Image Encoding
- ural 1008 Image Encoding
- ural 1008. Image Encoding
- URAL--1008. Image Encoding
- 1008. Image Encoding(BFS)
- HDR Image encoding formats
- 【BFS】ural 1837
- 【BFS】ural 1033
- URAL 1080 Map Coloring (BFS)
- URAL 1325Dirt(BFS)
- ural 1106. Two Teams -bfs
- Ural 1033 Labyrinth(bfs)
- Regular Express
- WINCE两个小时学会DirectDraw编程
- 一步一步学Linq to sql(七):并发与事务
- Android利用NDK实现C++开发
- 一步一步学Linq to sql(八):继承与关系
- URAL 1008 Image encoding [BFS]
- Injecting techniques
- Linux下安装、配置ACE
- 一步一步学Linq to sql(九):其它补充
- spring事务配置
- 网站变灰色代码方法大集合(站点哀悼代码之用)
- 使用Windows Debug 工具来侦测堆崩溃
- PS肤色调整19大秘诀
- 一步一步学Linq to sql(十):分层构架的例子