码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • A. Three Doors


    time limit per test

    2 seconds

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    There are three doors in front of you, numbered from 11 to 33 from left to right. Each door has a lock on it, which can only be opened with a key with the same number on it as the number on the door.

    There are three keys — one for each door. Two of them are hidden behind the doors, so that there is no more than one key behind each door. So two doors have one key behind them, one door doesn't have a key behind it. To obtain a key hidden behind a door, you should first unlock that door. The remaining key is in your hands.

    Can you open all the doors?

    Input

    The first line contains a single integer tt (1≤t≤181≤t≤18) — the number of testcases.

    The first line of each testcase contains a single integer xx (1≤x≤31≤x≤3) — the number on the key in your hands.

    The second line contains three integers a,ba,b and cc (0≤a,b,c≤30≤a,b,c≤3) — the number on the key behind each of the doors. If there is no key behind the door, the number is equal to 00.

    Values 1,21,2 and 33 appear exactly once among x,a,bx,a,b and cc.

    Output

    For each testcase, print "YES" if you can open all the doors. Otherwise, print "NO".

    Example

    input

    Copy

     
    

    4

    3

    0 1 2

    1

    0 3 2

    2

    3 1 0

    2

    1 3 0

    output

    Copy

    YES
    NO
    YES
    NO

    解题说明:此题是一道模拟题,判断门后是否有钥匙能开下一扇门,判断两次门后的值不为0即可。

    1. #include
    2. int main()
    3. {
    4. int testcases;
    5. int x;
    6. int a[4];
    7. scanf("%d", &testcases);
    8. while (testcases--)
    9. {
    10. scanf("%d", &x);
    11. scanf("%d%d%d", &a[0], &a[1], &a[2]);
    12. if (a[x - 1] != 0 && a[a[x - 1] - 1] != 0)
    13. {
    14. printf("YES\n");
    15. }
    16. else
    17. {
    18. printf("NO\n");
    19. }
    20. }
    21. return 0;
    22. }

  • 相关阅读:
    如何压缩ppt文件的大小?
    MySQL 中 count() 和 count(1) 有什么区别?哪个性能最好?
    1.2 课程架构介绍:STM32H5 芯片生命周期管理与安全调试
    【附源码】计算机毕业设计SSM图书销售系统设计
    认识运营商机房
    热赛道上的冷思考:乘数效应才是东数西算的根本要求
    PAT 乙级 1033旧键盘打字
    力扣(leetcode)第485题最大连续1的个数(Python)
    --2023-09-2
    交通运输行业经销商渠道管理系统高效协同,提高便捷化水平
  • 原文地址:https://blog.csdn.net/jj12345jj198999/article/details/126336057
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号