Y2K Accounting Bug

来源:互联网 发布:京东商城数据库设计 编辑:程序博客网 时间:2024/05/21 08:55

Y2K Accounting Bug
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 13229 Accepted: 6718

Description

Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc. 
All what they remember is that MS Inc. posted a surplus or a deficit each month of 1999 and each month when MS Inc. posted surplus, the amount of surplus was s and each month when MS Inc. posted deficit, the deficit was d. They do not remember which or how many months posted surplus or deficit. MS Inc., unlike other companies, posts their earnings for each consecutive 5 months during a year. ACM knows that each of these 8 postings reported a deficit but they do not know how much. The chief accountant is almost sure that MS Inc. was about to post surplus for the entire year of 1999. Almost but not quite. 

Write a program, which decides whether MS Inc. suffered a deficit during 1999, or if a surplus for 1999 was possible, what is the maximum amount of surplus that they can post.

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.

Sample Input

59 237375 743200000 8496942500000 8000000

Sample Output

11628300612Deficit

这个题看了半个小时还是一脸蒙蔽不知道什么意思=-=,还是找旁边人给翻译了以下。

原来是MS公司在1999这一年张贴盈余S和赤字D。每一个月的盈余相同,赤字也相同。它很特别,每5个月张贴一次,也就是1-6、2-7、以此类推。

总共8次每次都是亏损的,问你这一年有没有可能盈余,如果可以求最大盈余。

╮(╯▽╰)╭,总算是弄懂意思了,原来题也不是很难5个月是亏损,但是年要盈余且最大无非就是这样子的:

ssssssssssss5个月都是盈余显然是不可能的。

ssssdssssdss可以√

sssddsssddss

ssdddssdddss

sddddsddddsd

dddddddddddd这个显然是不行的了。

为什么是这样子呢,这样循环可以确保每次都和第一个5月相同。这样我们只要确保第一个5月的S尽量多D尽量少并且总的是亏损(你若在某个地方多加一个s那么必定会走到那个点上使的这5个月不是亏损了)这样全年就最多了,而且S是放在前面的。

#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int main(){    int s,d;    int i;    while(~scanf("%d%d",&s,&d))    {        for(i=4;i>=0;--i)    {        if(s*i-d*(5-i)<0)break;    }    if(i==0)printf("Deficit\n");    else    {        int ans;        if(i>=2)ans=s*(i*2+2)-d*(5-i)*2;        else ans=s*(i*2+1)-d*((5-i)*2+1);        if(ans>0)printf("%d\n",ans);        else printf("Deficit\n");    }    }    return 0;}



0 0