长沙理工大学第十二届ACM大赛-重现赛C 安卓图案解锁 (模拟)
链接:https://ac.nowcoder.com/acm/contest/1/C
来源:牛客网
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld
题目描述
输入描述:
多组输入
每组输入占一行,包含一串数字(1~9),长度不超过30
输出描述:
输出这个安卓图案解锁是否合法,如果合法输出"YES",反之输出"NO" (请参照样例输出,不要输出引号)
输出
YES
NO
YES
NO 思路:
建立 一个二维数组 isok[i][j] 代表 从i走到j是否能走。
用一个数组 cnt[i] 来记录数字i在字符串中出现的次数。 然后直接模拟即可。
(题目中有错误的描述, 1-3-9 应该是 1-5-9 ) 出题人也不改题面,无奈啊。
细节见代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
char s[];
int isok[][];
int cnt[];
int main()
{
// freopen("D:\\code\\text\\input.txt","r",stdin);
//freopen("D:\\code\\text\\output.txt","w",stdout);
while(cin>>s)
{
int len=strlen(s);
// if(len>9)
// {
// cout<<"NO"<<endl;
// continue;
// }
int flag=;
repd(i,,)
{
cnt[i]=;
repd(j,,)
{
isok[i][j]=;
}
}
isok[][]=isok[][]=;
isok[][]=isok[][]=;
isok[][]=isok[][]=;
isok[][]=isok[][]=;
isok[][]=isok[][]=;
isok[][]=isok[][]=;
isok[][]=isok[][]=;
isok[][]=isok[][]=;
int last=s[]-'';
int x;
x=last;
cnt[x]++;
if(x==)
{
isok[][]=isok[][]=;
}else if(x==)
{
isok[][]=isok[][]=;
}else if(x==)
{
isok[][]=isok[][]=;
isok[][]=isok[][]=;
isok[][]=isok[][]=;
isok[][]=isok[][]=;
}else if(x==)
{
isok[][]=isok[][]=;
}else if(x==)
{
isok[][]=isok[][]=;
}
rep(i,,len)
{
x=s[i]-'';
cnt[x]++;
if(!isok[last][x])
{
flag=;
break;
}else
{
if(x==)
{
isok[][]=isok[][]=;
}else if(x==)
{
isok[][]=isok[][]=;
}else if(x==)
{
isok[][]=isok[][]=;
isok[][]=isok[][]=;
isok[][]=isok[][]=;
isok[][]=isok[][]=;
}else if(x==)
{
isok[][]=isok[][]=;
}else if(x==)
{
isok[][]=isok[][]=;
}
}
last=x;
}
repd(i,,){
if(cnt[i]>){
flag=;
}
}
if(flag)
{
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
} } return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
长沙理工大学第十二届ACM大赛-重现赛C 安卓图案解锁 (模拟)的更多相关文章
- 长沙理工大学第十二届ACM大赛-重现赛 J 武藏牌牛奶促销
链接:https://ac.nowcoder.com/acm/contest/1/J 来源:牛客网 武藏牌牛奶促销 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他 ...
- 长沙理工大学第十二届ACM大赛-重现赛I 主持人的烦恼 (sort)
链接:https://ac.nowcoder.com/acm/contest/1/I 来源:牛客网 主持人的烦恼 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语 ...
- 长沙理工大学第十二届ACM大赛-重现赛 D 小M和天平 (01背包)
链接:https://ac.nowcoder.com/acm/contest/1/D 来源:牛客网 小M和天平 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 131072K,其他语言 ...
- 长沙理工大学第十二届ACM大赛-重现赛 B 日历中的数字 (实现)
链接:https://ac.nowcoder.com/acm/contest/1/B来源:牛客网 全屏查看题目 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他 ...
- 长沙理工大学第十二届ACM大赛-重现赛 G - 跑路ing
题目描述 vigoss18 辞职成功终于逃出了公司,但是没过太久,公司就发现vigoss18 的所作所为,于是派人来把他抓 回去. vigoss18 必须一直跑路,躲避公司的围捕.可以抽象的看成一个有 ...
- 长沙理工大学第十二届ACM大赛-重现赛 L - 选择困难症
题目描述 小L有严重的选择困难症. 早上起床后,需要花很长时间决定今天穿什么出门. 假设一共有k类物品需要搭配选择,每类物品的个数为Ai,每个物品有一个喜欢值Vj,代表小L对这件物品的喜欢程度. 小L ...
- 长沙理工大学第十二届ACM大赛-重现赛 K - 大家一起来数二叉树吧
题目描述 某一天,Zzq正在上数据结构课.老师在讲台上面讲着二叉树,zzq在下面发着呆. 突然zzq想到一个问题:对于一个n个节点,m个叶子的二叉树,有多少种形态呐?你能告诉他吗? 对于第一组样例的解 ...
- 长沙理工大学第十二届ACM大赛-重现赛
年轮广场 时间限制:1秒 空间限制:131072K 题目描述 在云塘校区,有一个很适合晒太阳的地方————年轮广场 年轮广场可以看成n个位置顺时针围成一个环. 这天,天气非常好,Mathon带着他的小 ...
- 长沙理工大学第十二届ACM大赛-重现赛 大家一起来数二叉树吧 (组合计数)
大意: 求n结点m叶子二叉树个数. 直接暴力, $dp[i][j][k][l]$表示第$i$层共$j$节点, 共$k$叶子, 第$i$层有$l$个叶子的方案数, 然后暴力枚举第$i$层出度为1和出度为 ...
随机推荐
- spring security跳过认证
在启动springboot的时候,给启动注解后添加这个exclude参数后接想要跳过的类就不会加载它了. @SpringBootApplication(exclude = { org.springfr ...
- sourcetree pull push需要密码问题
我的是mac,以mac版本的sourcetree 为例 第一步 项目仓库右上角设置 第二步.点击远程仓库. 点击仓库路径点击编辑 第三步 url/路径修改 原本.https://gitee.com ...
- leetcode-mid-backtracking -22. Generate Parentheses-NO
mycode 没有思路,大早上就有些萎靡,其实和上一个电话号码的题如出一辙啦 参考: class Solution(object): def generateParenthesis(self, ...
- 【洛谷T89359 扫雷】
题目链接 这个题有一个十分简单的做法 我们可以考虑位运算 按位异或(^) 异或,英文为exclusive OR,缩写成xor 异或(xor)是一个数学运算符.它应用于逻辑运算.异或的数学符号为“⊕”, ...
- 十八、RF中selenium2library构造函数中参数解释
def __init__(self, timeout=5.0, implicit_wait=0.0, ...
- 初识Nginx及其LNMP搭建
Nginx介绍 nginx www服务软件 俄罗斯人开发 开源 性能很高 web产品 大小780k c语言开发 本身是一款静态www软件,不能解析php jsp .do 最大特点 静态小文件(1m), ...
- 分布式任务队列 Celery
目录 目录 前言 简介 Celery 的应用场景 架构组成 Celery 应用基础 前言 分布式任务队列 Celery,Python 开发者必备技能,结合之前的 RabbitMQ 系列,深入梳理一下 ...
- c# AES128 加解密算法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- 关于mysql中修改某个字段类型,以及备份表中数据到新建的表中,从新建的表中移除数据到修改过的表中
1:修改表中某个字段的类型 alter table usertable MODIFY dddd VARCHAR(50); 其中MODIFY是指修改表中字段的属性 alter表示修改表的意思 2:备份表 ...
- Grass Planting
大致题意: 维护一棵树,支持两种操作: P x y x到y路径上的每条边的值+1:Q x y 询问x到y路径上所有边的值的和.Input第一行两个正整数,N,M表示点数和操作数:接下来N-1行每行两个 ...