A. Donut Shops(分类模拟)

, , 这题相信大家都能切出来,但是得讲究分类,快且准确

. a b < = c , 1 , , \color{Red}Ⅰ.当a*b<=c,说明商品1又是零售,单价由少,怎么买都划算

if(a*b<c)//单价少,还是零售 
	cout<<1<<" "<<-1<<endl;

. a b > c , 2 便 \color{Red}Ⅱ.当a*b>c,说明商品2平均下来还是比较便宜的

1 便 , 1 , 2 此时商品1想便宜,一定是只买1件商品,让商品2去买一盒

2 , 如果这样都是商品2划算,那么

if(a>=c)	cout<<-1<<" "<<b<<endl;

, 2 否则,就要凑商品2划算的时候。

2 , b , 1 商品2要划算,肯定买b的正数倍,不然还是可能被商品1靠零售的优势败下阵来

完整代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t,a,b,c;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>a>>b>>c;
		if(a*b<=c)//单价少,还是零售 
			cout<<1<<" "<<-1<<endl;
		else
		{
			if(a>=c)	cout<<-1<<" "<<b<<endl;
			else
			{
				int maxx=(1e9)/b;//买的越多越不容易出错 
				cout<<1<<" "<<maxx*b<<endl;
			}
		} 
	}
}

猜你喜欢

转载自blog.csdn.net/jziwjxjd/article/details/106966432