Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads

来源:互联网 发布:java iterator() 编辑:程序博客网 时间:2024/06/06 02:35

传送门


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 10 1 0 00 0 1 00 0 0 1
output
YES
input
0 1 1 01 0 1 01 1 0 00 0 0 1
output
NO
input
1 0 0 00 0 0 10 0 0 01 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.



题意:

车有三个方向 左中右 人有绿灯 如果是1的话代表绿灯可以通过。 问是不是会发生车祸。如果会撞上的话就YES 不会撞的话就NO。 同一条线上左中右都可能撞上所以YES。

比如第一个样例1 0 0 1 然后如果在2轨道向左转弯也许会撞上1 所以也要判断 另外还有直接从中间直通的情况就有可能撞上对面的轨道的人。

#include <bits/stdc++.h>//#include <ext/pb_ds/tree_policy.hpp>//#include <ext/pb_ds/assoc_container.hpp>//using namespace __gnu_pbds;using namespace std;#define pi acos(-1)#define endl '\n'#define me(x) memset(x,0,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0);#define rand() srand(time(0));typedef long long LL;typedef pair<int, int> pii;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;//const int dx[]={-1,0,1,0,-1,-1,1,1};//const int dy[]={0,1,0,-1,1,-1,1,-1};const int maxn=1e3+5;const int maxx=1e5+100;const double EPS=1e-9;const int MOD=1000000007;#define mod(x) ((x)%MOD);template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}//typedef tree<pt,null_type,less< pt >,rb_tree_tag,tree_order_statistics_node_update> rbtree;/*lch[root] = build(L1,p-1,L2+1,L2+cnt);    rch[root] = build(p+1,R1,L2+cnt+1,R2);中前*//*lch[root] = build(L1,p-1,L2,L2+cnt-1);    rch[root] = build(p+1,R1,L2+cnt,R2-1);中后*/long long gcd(long long a , long long b){if(b==0) return a;a%=b;return gcd(b,a);}inline int Scan(){    int res=0,ch,flag=0;    if((ch=getchar())=='-')flag=1;    else if(ch>='0' && ch<='9')res=ch-'0';    while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0';    return flag ? -res : res;}int a[4][4];int main(){    while (~scanf("%d%d%d%d", &a[0][0], &a[0][1], &a[0][2], &a[0][3]))    {        for (int i = 1; i < 4; i++) scanf("%d%d%d%d", &a[i][0], &a[i][1], &a[i][2], &a[i][3]);        int flag = 0;        for (int i = 0; i < 4; i++)        {            if (!a[i][3]) continue;            if (a[i][1] ||a[i][0]||a[i][2]|| a[(i + 2) % 4][1] || a[(i + 1) % 4][0] || a[(i - 1 + 4) % 4][2]) flag = 1;        }        if (flag) printf("YES\n");        else printf("NO\n");    }    return 0;}


原创粉丝点击