E

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.
题目的图片我粘不过来,可以看这个网页的图片
https://cn.vjudge.net/problem/838986/origin这里写链接内容

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 l, s, r, p — 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.

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int viss[5]= {0},vis[5]= {0};
    int dir[5][5]= {{4,3,2},{1,4,3},{2,1,4},{3,2,1}};
    int i,j,f=0;
    for(i=0; i<4; i++)
    {
        for(j=0; j<3; j++)
        {
            int a;
            scanf("%d",&a);
            if(a)
            {
                viss[dir[i][j]]=1;
                viss[i+1]=1;
            }
        }
        int b;
        scanf("%d",&b);
        if(b)
        {
            vis[i+1]=1;
        }
    }
    for(i=1;i<=4;i++)
    {
        if(vis[i]&&viss[i])
        {
            f=1;
            break;
        }
    }
    if(f==1)
    {
        printf("YES\n");
    }
    else printf("NO\n");
    return 0;
}

思路就是先把要走的路标记出来,比如说第一个路口要进那几个车道都写出来,然后当本路口的某一个车道是绿灯的时候,不仅要标记自己会出车,要进的车道也要标记要进车,这是为了下一步单独对某一个人行道操作的时候用,举个栗子,当当前的的人行道是绿灯的时候,如果本车道的viss[i]是1,就说明可能有别的车道要进我这里,或者我的本路口要出车,这样都会撞,最后统一输出

猜你喜欢

转载自blog.csdn.net/bhliuhan/article/details/80306876
E
e'e
e4e