CF1373A Donut Shops

题目描述
There are two rival donut shops.

The first shop sells donuts at retail: each donut costs aa dollars.

The second shop sells donuts only in bulk: box of bb donuts costs cc dollars. So if you want to buy xx donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to xx .

You want to determine two positive integer values:

how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn’t exist then that value should be equal to -1−1 . If there are multiple possible answers, then print any of them.

The printed values should be less or equal to 10^910
9
. It can be shown that under the given constraints such values always exist if any values exist at all.
输入格式
The first line contains a single integer tt ( 1 \le t \le 10001≤t≤1000 ) — the number of testcases.

Each of the next tt lines contains three integers aa , bb and cc ( 1 \le a \le 10^91≤a≤10
9
, 2 \le b \le 10^92≤b≤10
9
, 1 \le c \le 10^91≤c≤10
9
).

输出格式
For each testcase print two positive integers. For both shops print such xx that buying xx donuts in this shop is strictly cheaper than buying xx donuts in the other shop. xx should be greater than 00 and less or equal to 10^910
9
.

If there is no such xx , then print -1−1 . If there are multiple answers, then print any of them.

题意翻译
有两个甜甜圈店。

第一家店零售甜甜圈:每个甜甜圈的价格为 aa 美元。

第二家店散装出售甜甜圈:一盒 bb 个甜甜圈的价格为 cc 美元。 只能整盒买。

在第一家商店中购买几个甜甜圈比在第二家商店中便宜?

在第二家商店中购买几个甜甜圈比在第一家商店中便宜?

如果其中某个答案不存在,输出 -1−1。 如果有多个可能的答案,请输出任意一个。

输出的值应 \leq 10^9≤10
9
。 可以证明,如果存在答案,那么在 10^910
9
内也必定存在答案。

输入输出样例
输入 #1复制
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
输出 #1复制
-1 20
8 -1
1 2
-1 1000000000
说明/提示
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 33 or 55 donuts you’ll have to buy a box of 1010 donuts for 44 dollars. 33 or 55 donuts in the first shop would cost you 1515 or 2525 dollars, respectively, however. For 2020 donuts you’ll have to buy two boxes for 88 dollars total. Note that 33 and 55 are also valid answers for the second shop, along with many other answers.

In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 88 donuts cost 3232 dollars in the first shop and 4040 dollars in the second shop (because you have to buy two boxes). 1010 donuts will cost 4040 dollars in both shops, so 1010 is not a valid answer for any of the shops.

In the third testcase 11 donut costs 22 and 33 dollars, respectively. 22 donuts cost 44 and 33 dollars. Thus, 11 is a valid answer for the first shop and 22 is a valid answer for the second shop.

In the fourth testcase 10^910
9
donuts cost 10^{18}10
18
dollars in the first shop and 10^910
9
dollars in the second shop.

思路
两次a的操作等于一次b的操作,那么就看是两次a的花费高还是一次b的花费高
如果a+a高,就尽量多用b,那就先用b使min(x,y)等于0,然后再使abs(x-y)就是剩余的另一个数,再用a 使它等于0;
如果b高,就全用a,(x+y)次a的操作

代码

#include<bits/stdc++.h>
using namespace std;
int main() 
{
	long long int t,a,b,x,y;
	cin>>t;
	while(t--)
	{
		cin>>x>>y>>a>>b;
		if(a+a<=b)
		{
			cout<<abs(x+y)*a<<endl;
		}
		else
		{
			cout<<min(x,y)*b+abs(x-y)*a<<endl;
		}
		
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值