题意:图像的两种表示的相互转化。
好久没有做题了,相当的郁闷啊。。。wa了好久。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>
using namespace std;
const int N = 19;
int v[N][N];
int n;
struct NOD{
int x,y;
};
queue<NOD> que;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
bool oor(int x,int y)
{
if(x<1||x>10) return false;
if(y<1||y>10) return false;
return true;
}
char dd[]="RTLB";
void solve1()
{
int x,y=-1;
for(int i=1;i<=10;i++)
{
if(y!=-1) break;
for(int j=1;j<=10;j++)
if(v[i][j])
{
x = i,y = j;
break;
}
}
while(!que.empty()) que.pop();
NOD e,t;
e.x = x,e.y = y;
que.push(e);
printf("%d %d\n",x,y);
v[x][y] = 0;
while(!que.empty())
{
e = que.front();que.pop();
for(int i=0;i<4;i++)
{
int tx = e.x + dx[i],ty = e.y+dy[i];
if(v[tx][ty])
{
printf("%c",dd[i]);
v[tx][ty] = 0 ;
t.x = tx,t.y = ty;
que.push(t);
}
}
if(que.empty()) printf(".\n");
else printf(",\n");
}
}
void solve2(int x,int y)
{
NOD e,t;
e.x = x,e.y = y;
v[x][y] = 1;
while(!que.empty()) que.pop();
que.push(e);
char ch[10];
int ans = 1;
while(!que.empty())
{
e = que.front(); que.pop();
scanf("%s",ch);
for(int i=0;i<strlen(ch);i++)
if(ch[i]=='R')
{
t.x = e.x+1,t.y = e.y;
v[t.x][t.y] = 1;
que.push(t);ans++;
}else if(ch[i]=='T')
{
t.x = e.x,t.y = e.y+1;
v[t.x][t.y] = 1;
que.push(t);ans++;
}else if(ch[i]=='L')
{
t.x = e.x-1,t.y = e.y;
v[t.x][t.y] = 1;
que.push(t);ans++;
}else if(ch[i]=='B')
{
t.x = e.x,t.y = e.y-1;
v[t.x][t.y] = 1;
que.push(t);ans++;
}
}
printf("%d\n",ans);
for(int i=1;i<11;i++)
for(int j=1;j<11;j++)
if(v[i][j])
{
printf("%d %d\n",i,j);
}
}
int main()
{
//freopen("in.txt","r",stdin);
char ch[30];
while(gets(ch))
{
if(strlen(ch)>0) break;
}
int t = 0;
for(int i=0;i<strlen(ch);i++)
if(ch[i]==' ')
t = 1;
int a,b;
if(t==0)
{
sscanf(ch,"%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
//cout<<a<<" "<<b<<endl;
v[a][b] = 1;
}
solve1();
}else
{
sscanf(ch,"%d%d",&a,&b);
solve2(a,b);
}
return 0;
}