zoukankan      html  css  js  c++  java
  • A题

    A题

    题目描述

    A要去B的城市游玩,A在城市1居住,B在城市X居住,现在有一神奇的传送门从城市1依次通往城市N,还有另外一个奇神的传送门从城市N通往城市1。
    已知,神奇的传送门可以从城市1跑到2,2跑到3,...城市N-1跑到城市N,但是在传送的过程中不能进入某些特定的城市,奇神的传送门也是类似。
    那么已知数组a,其中ai代表着神奇的传送门能否进入城市i(ai=1代表可以,ai=0代表不可以),以及数组b,其中bi代表着奇神的传送门能否进入城市i。
    神奇的海螺想知道A能不能去B的城市玩。

    输入

    多组测试样例。
    每组测试样例的第一行有两个数字N和X,代表了城市的数量和B的居住地址(2 <= N <= 1000 2 <= X <= 1000)
    第二行给出数组a,第三行给出数组b。

    输出

    可行,则输出YES
    否则,输出NO

    样例输入

    5 3
    1 1 1 1 1
    1 1 1 1 1
    5 4
    1 0 0 0 1
    0 1 1 1 1
    5 2
    0 1 1 1 1
    1 1 1 1 1

    样例输出

    YES
    YES
    NO


    #include <bits/stdc++.h>
    using namespace std;
    int a[1000 + 5], b[1000 + 5];
    int main()
    {
        int n, x;
    
        while(~scanf("%d%d", &n, &x))
        {
            for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
            for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
    
    
            if(a[1] == 0)   puts("NO");
            else if(a[x] == 1)  puts("YES");
            else if(b[x] == 0)  puts("NO");
            else
            {
                int ok = 0;
                for(int i = x + 1; i <= n; i++)
                {
                    if(a[i] == 1 && b[i] == 1)
                    {
                        ok = 1;
                        break;
                    }
                }
                if(ok)  puts("YES");
                else puts("NO");
            }
        }
    
        return 0;
    }
    

      

  • 相关阅读:
    详解 ES6 Modules
    es6常用基础合集
    透彻掌握Promise的使用,读这篇就够了
    Initialization of deep networks
    Logistic Regression and Gradient Descent
    一定要在年轻的时候读最难的书
    DEEP LEARNING WITH STRUCTURE
    我和NLP的故事(转载)
    Common Pitfalls In Machine Learning Projects
    C++中debug和release的区别 . 转载
  • 原文地址:https://www.cnblogs.com/qing123tian/p/11110895.html
Copyright © 2011-2022 走看看