标签:style http color java 使用 os io strong
描述
众所周知,lfq198502非常喜欢玩连连看游戏。连连看游戏 ,只要将相同花色的两张牌用三根以内的直线连在一起就可以消除, 规则简单容易上手 。
操作:第一次使用鼠标点击棋盘中的棋子,该棋子此时为“被选中”,以特殊方式显示;再次以鼠标点击其他棋子,若该棋子与被选中的棋子图案相同,且把第一个棋子到第二个棋子连起来,中间的直线不超过 3 根,则消掉这一对棋子,否则第一颗棋子恢复成未被选中状态,而第二颗棋子变成被选中状态。
我们可以把连连看的界面想象成一个10×10的方格,每个方格内都放有一种类型的图案或者为空,简单起见,我们用不同的字符代表不同的图案,空格表示没有图案。你的任务是,给出游戏的初始界面,和游戏过程中lfq198502鼠标点击的坐标记录,判断他在这些操作后是否将图案全部消完。
输入
输入包含多组测试情况,每组情况数据包含两部分。
第一部分:10行字符串,每行包含10个字符(空格表示该方格为空,其他字符表示方格中的有用该字符表示的图案),表示游戏的初始界面。
第二部分:首先是一个整数n,表示lfq198502的鼠标点击次数;接下来的n行,每行两个整数x,y(1≤x≤10, 1≤y≤10),表示鼠标点击位置所在的行和列。
输出
每组测试情况输出一行。如果lfq198502能够将图案全部消除,输出“Yes,all patterns are eliminated!”;否则,输出“No,m pattern(s) are left!”。
样例输入
样例输出
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
char map[15][15];
int oldx,oldy,newx,newy;
int fx[]={1,0,-1,0,1};
int vis[15][15];
struct node
{
int x,y;
int w;
int fx;
};
int bfs()
{
node a,b;
a.x=oldx;a.y=oldy;
a.w=0;a.fx=-1;
memset(vis,-1,sizeof vis);
if(map[a.x][a.y]!=map[newx][newy])
{
oldx=newx;oldy=newy;
return 0;
}
vis[a.x][a.y]=0;
queue<node>q;
q.push(a);
while(!q.empty())
{
a=q.front();
q.pop();
for(int i=0;i<4;i++)
{
b.x=a.x+fx[i];
b.y=a.y+fx[i+1];
if(b.x<0||b.x>11||b.y<0||b.y>11)continue;
if((a.fx+i)%2==0||a.fx==-1)
b.w=a.w;
else
b.w=a.w+1;
b.fx=i;
if(b.w>2)continue;
if(b.x==newx&&b.y==newy)
{
map[oldx][oldy]=' ';
map[newx][newy]=' ';
oldx=0;oldy=0;
return 2;
}
if(map[b.x][b.y]!=' ')continue;
if(vis[b.x][b.y]==-1||vis[b.x][b.y]>b.w)
{
vis[b.x][b.y]=b.w;
q.push(b);
}
}
}
oldx=newx;oldy=newy;
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(map,' ',sizeof map);
getchar();
int i,j,x,y,k,m=0,s=0;
for(i=1;i<=10;i++)
{
gets(map[i]+1);
for(j=1;j<=10;j++)
if(map[i][j]!=' ')
s++;
}
/*cout<<endl;
for(i=1;i<=10;i++)
cout<<map[i]<<endl;*/
//cout<<s<<endl;
oldx=0;oldy=0;
scanf("%d",&k);
for(i=0;i<k;i++)
{
scanf("%d%d",&x,&y);
if(map[x][y]==' ')
{
oldx=0;oldy=0;
continue;
}
if((oldx==0&&oldy==0)||(oldx==x&&oldy==y))
{
oldx=x;oldy=y;
}else{
newx=x;newy=y;
m += bfs();
//cout<<m<<endl;
}
}
if(m==s)
{
printf("Yes,all patterns are eliminated!\n");
}else{
printf("No,%d pattern(s) are left!\n",(s-m));
}
}
return 0;
}
标签:style http color java 使用 os io strong
原文地址:http://blog.csdn.net/fljssj/article/details/38412973