Codeforces Round #361 (Div. 2) A. Mike and Cellphone ( 模拟 )

A. Mike and Cellphone

题意:

 给定一个0-9数字键盘,随后输入一个操作序列,

问该操作序列在键盘上形成的手势是否是唯一的,是YES,否NO。

计算起点与其他点位置之间的差额(方向队列记录),从头开始,直接寻找,模拟过程;

AC代码:

 

#include <cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
struct  node
{
	int x;
	int y;
};
using namespace std;
int ans[6][5] = {-1,-1,-1,-1,-1,-1 ,1, 2, 3,-1,-1, 4, 5, 6,-1,-1, 7, 8, 9,-1,-1,-1, 0,-1,-1,-1,-1,-1,-1,-1};
int main()
{
	int n; 
	node q[10];
	q[0].x = 4; q[0].y = 2;
	q[1].x = 1; q[1].y = 1;
	q[2].x = 1; q[2].y = 2;
	q[3].x = 1; q[3].y = 3;
	q[4].x = 2; q[4].y = 1;
	q[5].x = 2; q[5].y = 2;
	q[6].x = 2; q[6].y = 3;
	q[7].x = 3; q[7].y = 1;
	q[8].x = 3; q[8].y = 2;
	q[9].x = 3; q[9].y = 3;
	while (scanf("%d",&n)!=EOF) 
	{
		node b;
		queue<node>dir;
		char a[100];
		int k;
		scanf("%s", a);
		for (int i = 0; i < n; i++)
		{
			int x = a[i] - '0';
			if (i == 0) { b = q[x]; k = x; }
			else
			{
				node task;
				 task.x = q[x].x - b.x;
				 task.y = q[x].y - b.y;
				 dir.push(task);
			}
		}
		int count;
		for (int i = 0; i <= 10; i++)
		{
			if (k == i) continue;
			queue<node>f = dir;
			 count = 0;
			while (!f.empty())
			{
				node task = f.front();   f.pop();
				int xx = q[i].x + task.x; int yy = q[i].y + task.y;
				if (xx >= 1 && xx <= 4 && yy >= 1 && yy<=3 && ans[xx][yy]!=-1 )
				{
					count++;
				} 
				if (count == n - 1) break;
			}
			if (count ==  n - 1) break;
		}
		if (count ==  n - 1)    printf("NO\n");
		else                    printf("YES\n");
	}
	return 0;
} 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值