Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 600600 points

Problem Statement

Ringo Mart, a convenience store, sells apple juice.

On the opening day of Ringo Mart, there were AA cans of juice in stock in the morning. Snuke buys BB cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are CC or less cans, DD new cans will be added to the stock by the next morning.

Determine if Snuke can buy juice indefinitely, that is, there is always BB or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.

Note that each test case in this problem consists of TT queries.

Constraints

  • 1≤T≤3001≤T≤300
  • 1≤A,B,C,D≤10181≤A,B,C,D≤1018
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

TT
A1A1 B1B1 C1C1 D1D1
A2A2 B2B2 C2C2 D2D2
::
ATAT BTBT CTCT DTDT

In the ii-th query, A=Ai,B=Bi,C=Ci,D=DiA=Ai,B=Bi,C=Ci,D=Di.

Output

Print TT lines. The ii-th line should contain Yes if Snuke can buy apple juice indefinitely in the ii-th query; No otherwise.


Sample Input 1 Copy

Copy
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985

Sample Output 1 Copy

Copy
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes

In the first query, the number of cans of juice in stock changes as follows: (D represents daytime and N represents night.)

99 →D 22 →N 1111 →D 44 →N 1313 →D 66 →N 66 →D x

In the second query, the number of cans of juice in stock changes as follows:

99 →D 22 →N 1111 →D 44 →N 1313 →D 66 →N 1515 →D 88 →N 88 →D 11 →N 1010 →D 33 →N 1212 →D 55 →N 1414 →D 77 →N 77 →D 00 →N 99 →D 22 →N 1111 →D …

and so on, thus Snuke can buy juice indefinitely.


Sample Input 2 Copy

Copy
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1

Sample Output 2 Copy

Copy
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No 首先可以直接判断的情况是a < b的情况第一天就不够买的,再就是d < b的情况,每天买b个,而当总量不多于c时才只能补充d,显然补充的量不及买的量,肯定会买完。
再就是c + 1 >= b的情况下,肯定时买不完的,因为一旦量小于等于c就会进行补充,而在量大于c的情况下总是不可能买断的。
对于一般的情况其实就是c < a - bx + dy < b 如果有解的话,就会出现不补充但是总量小于b的情况,这是肯定可以买完的,否则就是永远买不完的。
对于这个不等式,移项得到a - b < bx - dy < a - c,如果bx - dy在这个区间内有解,那么区间内存在一个值能被gcd(b,d)整除,但是这个区间是开区间(a - b,a - c),
具体判断存在的方法是,如果a - b < t < a - c,t % gcd(b,d) == 0,那么就是可以买完的("No"),那么a - c - 1 >= t,显然对于整型来说t / gcd(b,d) - (a - b) / gcd(b,d) > 0,
也就是(a - c - 1) / gcd(b,d) - (a - b) / gcd(b,d) > 0,否则就是买不完的("Yes").
java代码:
import java.util.*;

public class Main {
static long gcd(long a,long b) {
if(b == 0)return a;
return gcd(b,a % b);
}
static boolean check(long a,long b,long c,long d) {
if(a < b || d < b)return false;
if(c + 1 >= b)return true;
///如果某天之后 剩下的多于c(不需要增加) 但是却小于b 那么次日肯定不够
///实际上就是c < a - bx + dy < b有解的话就是No
///移项的a - b < bx - dy < a - c
///根据欧几里德扩展定理 就是说(a-b,a-c)之间是否有gcd(b,d)的倍数 即是否有解
long g = gcd(b,d);
return (a - c - 1) / g - (a - b) / g <= 0;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i = 0;i < t;i ++) {
long a = in.nextLong();
long b = in.nextLong();
long c = in.nextLong();
long d = in.nextLong();
if(check(a,b,c,d))System.out.println("Yes");
else System.out.println("No");
}
} }

c代码:

#include <stdio.h>
long long gcd(long long a,long long b){
return b ? gcd(b,a % b) : a;
}
int check(long long a,long long b,long long c,long long d){
if(a < b || d < b)return ;
if(c + >= b)return ;
long long g = gcd(b,d);
return (a - c - ) / g - (a - b) / g <= ;
}
int main() {
int t;
long long a,b,c,d;
scanf("%d",&t);
while(t --){
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
if(check(a,b,c,d)){
printf("Yes\n");
}
else{
printf("No\n");
}
}
}

AtCoder Grand Contest #026 B - rng_10s的更多相关文章

  1. AtCoder Grand Contest 026 (AGC026) E - Synchronized Subsequence 贪心 动态规划

    原文链接https://www.cnblogs.com/zhouzhendong/p/AGC026E.html 题目传送门 - AGC026E 题意 给定一个长度为 $2n$ 的字符串,包含 $n$ ...

  2. AtCoder Grand Contest 026 D - Histogram Coloring

    一列中有两个连续的元素,那么下一列只能选择选择正好相反的填色方案(因为连续的地方填色方案已经确定,其他地方也就确定了) 我们现将高度进行离散化到Has数组中,然后定义dp数组 dp[i][j] 表示前 ...

  3. AtCoder Grand Contest #026 C - String Coloring

    Time Limit: 3 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement You are given a st ...

  4. AtCoder Grand Contest #026 A - Colorful Slimes 2

    Time Limit: 2 sec / Memory Limit: 1024 MB Score : 200200 points Problem Statement Takahashi lives in ...

  5. Atcoder Grand Contest 026 (AGC026) F - Manju Game 博弈,动态规划

    原文链接www.cnblogs.com/zhouzhendong/AGC026F.html 前言 太久没有发博客了,前来水一发. 题解 不妨设先手是 A,后手是 B.定义 \(i\) 为奇数时,\(a ...

  6. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  7. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  8. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  9. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

随机推荐

  1. Nginx 一些常用的URL 重写方法

    url重写应该不陌生,不管是SEO URL 伪静态的需要,还是在非常流行的wordpress里,重写无处不在. 1. 在 Apache 的写法 RewriteCond  %{HTTP_HOST}  n ...

  2. Spring Boot从入门到实战:整合Web项目常用功能

    在Web应用开发过程中,一般都涵盖一些常用功能的实现,如数据库访问.异常处理.消息队列.缓存服务.OSS服务,以及接口日志配置,接口文档生成等.如果每个项目都来一套,则既费力又难以维护.可以通过Spr ...

  3. mysql解决中文乱码

    mysql>use mydb; mysql>alter database mydb  character set utf8;! 这种方法只对设置后重新创建的表有效,对已存在的表无效 des ...

  4. servletResponse 控制浏览器缓存

    //当访问一些资源文件时,我们希望,访问一次后,资源文件能够在缓存在浏览器中,当我们再次访问该资源时 //直接从缓存中去取,这样可以减少服务器的压力 package response; import ...

  5. linux uart驱动——uart原理(一)

    UART(Universal Asynchronous Receiver and Transmitter)通用异步收发器(异步串行通信口),是一种通用的数据通信协议,它包括了RS232.RS499.R ...

  6. Top 10 Open Source Bug Tracking System系统

    Bugzilla http://www.bugzilla.org/ Mantis php http://www.mantisbt.org/ Trac Python also provides wiki ...

  7. css选择器参考手册

    选择器 例子 例子描述 CSS .class .intro 选择 class="intro" 的所有元素. 1 #id #firstname 选择 id="firstna ...

  8. JavaMelody tomcat应用监控

    1 下载相关jar包,maven地址 测试发现 1.57.0版本tomcat6工程登陆报错,改用版本 1.50.0是正常的 <dependency> <groupId>net. ...

  9. WPF中的ListBox实现按块显示元素的方法

    本文实例讲述了WPF中的ListBox实现按块显示元素的方法.分享给大家供大家参考,具体如下: 注意:需要设置ListBox的属性 ScrollViewer.HorizontalScrollBarVi ...

  10. 利用Docker Compose快速搭建本地测试环境

    前言 Compose是一个定义和运行多个Docker应用的工具,用一个YAML(dockder-compose.yml)文件就能配置我们的应用.然后用一个简单命令就能启动所有的服务.Compose编排 ...