POJ_2586_Y2K Accounting Bug_英语、贪心

来源:互联网 发布:mysql select 锁表 编辑:程序博客网 时间:2024/06/12 20:26

不知不觉回来训练都一周了,我一直这么逗比真的好吗?


题意:

我自认为英语还不错,然后这个题还是没读懂。。。

已知某公司这年每个月要么亏损d要么盈利s,并且已知每五个连续的月的总利润都是亏损的,求该公司这一年最多能盈利多少,如果不能盈利输出赤字的英语单词。



Input

Input is a sequence of lines, each containing two positive integers s and d.

Output

For each line of input, output one line containing either a single integer giving the amount of surplus for the entire year, or output Deficit if it is impossible.


可以根据s和t算一下每5个月最少有多少个月亏损,假设每个月都是盈利的,然后从第一个月开始的第一个五个月开始遍历,如果当前五个月中亏损月不足,就把最后几个月变成亏损月。因为从前往后遍历,把亏损月放在后面可以减少后面五月的亏损月。

代码如下:

#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>using namespace std;int s,d;const int a[]={0,2,4,6,9,12};int main(){while(scanf("%d%d",&s,&d)!=EOF){int cnt=0;while(s*(5-cnt)-d*cnt>=0)++cnt;int ans=(12-a[cnt])*s-a[cnt]*d;if(ans<0)puts("Deficit");elseprintf("%d\n",ans);}return 0;}


0 0
原创粉丝点击