1.题目描述:
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.
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.
On a single line, print "YES" if an accident is possible, and "NO" otherwise.
1 0 0 1 0 1 0 0 0 0 1 0 0 0 0 1
YES
0 1 1 0 1 0 1 0 1 1 0 0 0 0 0 1
NO
1 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0
NO
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.
2.题意概述:
一个十字路口有红绿灯控制的四个方向,给你每个方向的车辆将要行驶的情况(直走、左转、右转)和这个车道前行人是否横向通行,问你在这种情况下是否可能发生交通事故?
3.解题思路:
直接模拟判断四个车道好了,比如第1个车道,如果有车辆左转,那么就去看它左边的车道(4车道)是否有行人横行,直行右转也是一样的道理!还有注意的是,如果这个车道有车辆要通行的话,那么本身车道不能有行人横行,这个也是一个可能WA的地方。
4.AC代码:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100010
#define lson root << 1
#define rson root << 1 | 1
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
int a[5][5];
bool check(int x)
{
if (x == 1)
{
for (int i = 1; i <= 3; i++)
if (a[x][i])
{
if (i == 1 && (a[4][4] || a[x][4]))
return 0;
if (i == 2 && (a[3][4] || a[x][4]))
return 0;
if (i == 3 && (a[2][4] || a[x][4]))
return 0;
}
return 1;
}
if (x == 2)
{
for (int i = 1; i <= 3; i++)
if (a[x][i])
{
if (i == 1 && (a[1][4] || a[x][4]))
return 0;
if (i == 2 && (a[4][4] || a[x][4]))
return 0;
if (i == 3 && (a[3][4] || a[x][4]))
return 0;
}
return 1;
}
if (x == 3)
{
for (int i = 1; i <= 3; i++)
if (a[x][i])
{
if (i == 1 && (a[2][4] || a[x][4]))
return 0;
if (i == 2 && (a[1][4] || a[x][4]))
return 0;
if (i == 3 && (a[4][4] || a[x][4]))
return 0;
}
return 1;
}
if (x == 4)
{
for (int i = 1; i <= 3; i++)
if (a[x][i])
{
if (i == 1 && (a[3][4] || a[x][4]))
return 0;
if (i == 2 && (a[2][4] || a[x][4]))
return 0;
if (i == 3 && (a[1][4] || a[x][4]))
return 0;
}
return 1;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
for (int i = 1; i <= 4; i++)
for (int j = 1; j <= 4; j++)
scanf("%d", &a[i][j]);
bool flag = 1;
for (int i = 1; i <= 4; i++)
if (!check(i))
{
flag = 0;
break;
}
puts(flag ? "NO" : "YES");
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return 0;
}