A. Mike and Cellphone(cf#361)

Mike不慎将手机遗失在海滩上,仅凭手指记忆拨打旧号码。通过分析按键移动来判断是否能确定拨出的号码唯一。此问题涉及算法与逻辑思维。

A. Mike and Cellphone
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:

Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":

Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?

Input

The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.

The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.

Output

If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.

Otherwise print "NO" (without quotes) in the first line.

Examples
input
3
586
output
NO
input
2
09
output
NO
input
9
123456789
output
YES
input
3
911
output
YES
Note

You can find the picture clarifying the first sample case in the statement above.


#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    char a[15];
    int b[10];
    memset(b,0,sizeof(b));
    scanf("%d",&n);
    scanf("%s",a);
    for(int i=0;i<strlen(a);i++)
    {
        b[a[i]-'0']=1;
    }
    if(b[1]+b[2]+b[3]>0&&b[0]+b[1]+b[4]+b[7]>0&&b[3]+b[6]+b[9]+b[0]>0&&b[7]+b[9]+b[0]>0)
        printf("YES\n");
    else printf("NO\n");
    return 0;
}

内容概要:本文围绕“考虑电能交互的冷热电区域多微网系统双层多场景协同优化配置”的Matlab代码实现展开,提出一种结合电能交互机制的双层优化模型,用于解决冷、热、电多能耦合背景下多微网系统的协同规划与运行问题。研究采用多场景分析方法应对可再生能源出力与负荷需求的不确定性,通过上层规划设备容量配置与下层优化多时段运行策略的联动,提升系统在复杂环境下的经济性、鲁棒性与能源利用效率。所提供的Matlab代码集成了建模、求解(如YALMIP+CPLEX)与结果可视化全流程,涵盖场景生成与削减、双层优化结构设计及多能流协同调度等关键技术环节,为综合能源系统优化提供了完整的算法实现与技术参考。; 适合人群:具备电力系统、综合能源系统或优化建模背景,熟悉Matlab编程与数学规划方法,正在从事相关领域科研或工程设计工作的研究生、高校研究人员及能源行业技术人员。; 使用场景及目标:①开展冷热电联供(CCHP)多微网系统的容量规划与运行优化研究;②支撑含分布式能源、储能及多能转换设备的综合能源系统多目标、多场景优化建模;③学习与复现双层优化、分布鲁棒优化及场景分析等先进优化方法在能源系统中的实际应用。; 阅读建议:建议结合配套文献与代码同步研读,重点理解双层模型的构建逻辑、变量耦合关系与求解技巧,关注场景生成方法与YALMIP调用细节,通过调整参数、修改目标函数等方式进行仿真实验,以深化对系统优化机理的掌握。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值