CF - 812A. Sagheer and Crossroads - 模拟

1.题目描述:

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.


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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值