poj2586

//poj2586 读题好难,我都怀疑自己英语了。。。
//给你盈利和亏损额度,每5个月发布一次,必须总的是亏的,但是保证亏的最少 1-5 2-6... 
//求这样下去12个月的最大盈利是多少 ?(虽然5个月都会亏, 但是连续下来时有可能盈利的) 
//wa了一次,没有考虑到全年都是亏损的情况 
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main()
{
	int s, d;
	while(cin>>s>>d)
	{
		int x, y;
		for(int i = 4; i >= 0; i--)
		{
			//5个月一次循环的样子,所以5个月亏n次,代表了12个月会亏 2n次
			x = i;
			y = 5 - i;
			if(s * x < d * y) 
			{
				break;
			}
 		}
 		int surplus = 0;
 		if(x != 1 && x != 0)
 			surplus = s * (12-2*y) - d * y * 2; 
		else if(x == 1)
			surplus = s * 3 - 9 * d;
		else if(x == 0)
			surplus = -12 * d;
		if(surplus > 0)
		{
			cout<<surplus<<endl;
		}
		else
			cout<<"Deficit"<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值