CF1538G.Gift Set

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp has xx of red and yy of blue candies. Using them, he wants to make gift sets. Each gift set contains either aa red candies and bb blue candies, or aa blue candies and bb red candies. Any candy can belong to at most one gift set.

Help Polycarp to find the largest number of gift sets he can create.

For example, if x=10x = 10, y=12y = 12, a=5a = 5, and b=2b = 2, then Polycarp can make three gift sets:

  • In the first set there will be 55 red candies and 22 blue candies;
  • In the second set there will be 55 blue candies and 22 red candies;
  • In the third set will be 55 blue candies and 22 red candies.

Note that in this example there is one red candy that Polycarp does not use in any gift set.

Polycarp 有 xx 颗红色糖果和 yy 颗蓝色糖果。他想用这些糖果制作礼品套装。每个礼品套装包含以下两种形式之一:aa 颗红色糖果和 bb 颗蓝色糖果,或 aa 颗蓝色糖果和 bb 颗红色糖果。每颗糖果最多只能属于一个礼品套装。

请帮助 Polycarp 求出他最多能制作多少个礼品套装。

例如,若 x=10x = 10,y=12y = 12,a=5a = 5,且 b=2b = 2,则 Polycarp 可以制作三个礼品套装:

  • 第一个套装包含 55 颗红色糖果和 22 颗蓝色糖果;
  • 第二个套装包含 55 颗蓝色糖果和 22 颗红色糖果;
  • 第三个套装包含 55 颗蓝色糖果和 22 颗红色糖果。

注意,在该示例中,有一颗红色糖果未被用于任何礼品套装。

输入格式

The first line contains an integer tt (1≤t≤1041 \le t \le 10^4). Then tt test cases follow.

Each test case consists of a single string containing four integers xx, yy, aa, and bb (1≤x,y,a,b≤1091 \le x, y, a, b \le 10^9).

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)。随后是 tt 组测试用例。

每组测试用例由一个字符串组成,其中包含四个整数 xx、yy、aa 和 bb(1≤x,y,a,b≤1091 \le x, y, a, b \le 10^9)。

输出格式

For each test case, output one number — the maximum number of gift sets that Polycarp can make.

对于每个测试用例,输出一个数字——Polycarp 能够制作的礼物套装的最大数量。

输入输出样例

  • 输入#1

    9
    10 12 2 5
    1 1 2 2
    52 311 13 27
    1000000000 1000000000 1 1
    1000000000 1 1 1000000000
    1 1000000000 1000000000 1
    1 2 1 1
    7 8 1 2
    4 1 2 3

    输出#1

    3
    0
    4
    1000000000
    1
    1
    1
    5
    0

输入解题思路,AI测评打分。不知道怎么写?

首页