zoukankan      html  css  js  c++  java
  • Round #417 A. Sagheer and Crossroads(Div.2)

    Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (l — left, s — straight, r — right) and a light p for a pedestrian crossing.

    An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.

    Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible.

    Input

    The input consists of four lines with each line describing a road part given in a counter-clockwise order.

    Each line contains four integers lsrp — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.

    Output

    On a single line, print "YES" if an accident is possible, and "NO" otherwise.

    Examples
    input
    1 0 0 1
    0 1 0 0
    0 0 1 0
    0 0 0 1
    output
    YES
    input
    0 1 1 0
    1 0 1 0
    1 1 0 0
    0 0 0 1
    output
    NO
    input
    1 0 0 0
    0 0 0 1
    0 0 0 0
    1 0 1 0
    output
    NO
    Note

    In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.

    In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur

     1 #include <iostream>
     2 #include <stdio.h>
     3 
     4 using namespace std;
     5 int main(){
     6     int a[5][5];
     7      for(int i=0;i<4;i++)
     8       for(int j=0;j<4;j++)
     9         scanf("%d",&a[i][j]);
    10 
    11         for(int i=0;i<4;i++){
    12             if(a[i][3]==1){
    13                 for(int j=0;j<3;j++)
    14                 if(a[i][j]==1){
    15                     printf("YES
    ");
    16                     return 0;   //思考break为什么不行
    17                 }
    18                 if(a[(i+1)%4][0]==1||a[(i+2)%4][1]==1||a[(i+3)%4][2]==1){
    19                     printf("YES
    ");
    20                     return 0;
    21                 }
    22             }
    23         }
    24         printf("NO
    ");
    25     return 0;
    26 }
  • 相关阅读:
    Hibernate 实体关联关系映射----总结
    原型模式(Prototype)解析例子
    Java 泛型的理解与等价实现
    Java:对象创建和初始化过程
    iReport的简单配置
    Python语言程序设计基础(第2版)课后习题答案 嵩天、礼欣、黄天羽版 高等教育出版社 试题和答案和解析
    编程精品教材:MATLAB程序设计与应用(第3版) 课后答案 刘卫国版 课后习题答案解析
    SkyWalking 快速接入实践
    Java基础 day01【前言、入门程序、常量、变量】
    python最新笔试题
  • 原文地址:https://www.cnblogs.com/z-712/p/7307738.html
Copyright © 2011-2022 走看看