CSU-2111: Lights in the Morning

2111: Lights in the Morning

Submit Page      Summary      Time Limit: 1 Sec       Memory Limit: 128 Mb       Submitted: 60       Solved: 27    

Description

You woke up late this morning and are in a rush to get to work. You are the kind of person who gets mad if they get unexpectedly stuck at traffic lights, so you are going to expect the unexpected! Your route to work is D kilometres long with N traffic lights along the way. Each traffic light has a red light and a green light. When the light is green, you may pass the traffic light, but when the light is red, you may not pass. When you leave your house, all of the traffic lights are red. For each traffic light, you know the first time that it will turn green. Once this happens, the traffic light will remain green for g minutes, then change to red for r minutes, then change back to green for g minutes, then red for r minutes and so on. These values may be different for each traffic light. If your car arrives at a traffic light at the moment that it changes (either green-to-red or red-to-green), assume that you will make it through. You travel at 1 kilometre per minute, so it takes D minutes to complete your journey. Determine whether or not you will get stopped at any of the traffic lights.

Input

The first line of input contains two integers N (1 ≤ N ≤ 1 000), which is the number of traffic lights, and D (2 ≤ D ≤ 109), which is the length of the journey. The next N lines describe the traffic lights. Each line contains four integers x (1 ≤ x < D), which is the location of the traffic light in kilometres from your home, a (1 ≤ a ≤ 109), which is the number of minutes after leaving home that the traffic light first turns green, g (1 ≤ g ≤ 109), which is the number of minutes that the traffic light remains green on each cycle, and r (1 ≤ r ≤ 109), which is the number of minutes that the traffic light remains red on each cycle. The locations of the traffic lights are all distinct.

Output

If you will make it through all of the traffic lights without stopping, display YES. Otherwise, display NO.

Sample Input

1 10
5 3 3 3

1 10
2 5 1 1

3 20
5 4 2 3
10 1 2 2
15 10 2 2

2 10
3 2 10 10
6 2 3 2

Sample Output

YES

NO

YES

NO

Hint

Source

South Pacific Divisionals

题意:某人从家去公司上班,每秒走一米。公司距离家d米。在路程中有n个红绿灯,红灯时间为r,绿灯时间为l。一开始都是红灯,且再过ai秒变成绿灯,问能不能不停下来等红绿灯,能YES,不能NO

题解:水题,模拟一发即可

AC代码

#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <stdio.h>
typedef long long ll;

using namespace std;

int main(){
    ll n, d, x, a, g, r;
    scanf("%lld %lld", &n, &d);
    	ll i = 0;
    	for(; i < n; i++){
    		scanf("%lld%lld%lld%lld", &x, &a, &g, &r);
    		if(x < a || ((x - a) % (g + r)) > g)
    			 break;
		}
		if(i == n)
			 printf("YES\n");
 		 else
 		 	 printf("NO\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37064135/article/details/80390175