Codeforces812A Sagheer and Crossroads2017-06-02 20:41 139人阅读评论

Codeforces812A Sagheer and Crossroads2017-06-02 20:41 139人阅读评论,第1张

Codeforces812A Sagheer and Crossroads 2017-06-02 20:41 139人阅读 评论(0) 收藏 A. Sagheer and Crossroads time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 3can
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.

———————————————————————————————————— 题目的意思是给出4个路口的车辆和人的红路灯状态,判断是否可能车撞人

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath> using namespace std; #define LL long long
const int inf=0x7fffffff; int main()
{
int a[10][10];
for(int i=1; i<=4; i++)
for(int j=1; j<=4; j++)
scanf("%d",&a[i][j]);
int flag=0;
if(a[1][4]==1&&(a[1][1]==1||a[1][2]==1||a[1][3]==1||a[2][1]==1||a[3][2]==1||a[4][3]==1))
printf("YES\n"),flag=1;
else if(a[2][4]==1&&(a[2][1]==1||a[2][2]==1||a[2][3]==1||a[3][1]==1||a[4][2]==1||a[1][3]==1))
printf("YES\n"),flag=1;
else if(a[3][4]==1&&(a[3][1]==1||a[3][2]==1||a[3][3]==1||a[4][1]==1||a[1][2]==1||a[2][3]==1))
printf("YES\n"),flag=1;
else if(a[4][4]==1&&(a[4][1]==1||a[4][2]==1||a[4][3]==1||a[1][1]==1||a[2][2]==1||a[3][3]==1))
printf("YES\n"),flag=1;
if(flag==0)
printf("NO\n"); return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/588998.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存