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

链接:http://codeforces.com/contest/689/problem/A

题意:有一个人手机丢了,他只记得手机密码的按键手势,但是不记得具体数字了,问这个按键手势是否唯一。

分析:标记下每一个点的转移方向,枚举0~9所有的起点看有多少种是合法的手势。

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=100010;
const int MAX=1000000100;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int INF=1000000010;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned long long ull;
char s[20];
int g[10][2]={4,2,1,1,1,2,1,3,2,1,2,2,2,3,3,1,3,2,3,3};
int f[15][2];
int out(int x,int y) {
    if (x==4&&y==2) return 0;
    if (x>0&&x<4&&y>0&&y<4) return 0;
    return 1;
}
int pd(int a,int len) {
    int i,x=g[a][0],y=g[a][1];
    for (i=1;i<len;i++) {
        x+=f[i][0];y+=f[i][1];
        if (out(x,y)) return 0;
    }
    return 1;
}
int main()
{
    int i,n,sum=0;
    scanf("%d", &n);
    scanf("%s", s);
    for (i=1;i<n;i++) {
        f[i][0]=g[s[i]-'0'][0]-g[s[i-1]-'0'][0];
        f[i][1]=g[s[i]-'0'][1]-g[s[i-1]-'0'][1];
    }
    for (i=0;i<10;i++) sum+=pd(i,n);
    if (sum==1) printf("YES\n");
    else printf("NO\n");
    return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值