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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值