Time Limit: 1000MS Memory Limit: 65536K
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 is a sequence of lines, each containing two positive integers s and d.
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.
59 237
375 743
200000 849694
2500000 8000000
Sample Output
116
28
300612
Deficit
题意就是公司有八次财政总结,每五个月总结一次(1-5,2-6,3-7,4-8,5-9,6-10,7-11,8-12),每次得出的总结都是亏损,每个月如果盈利只能盈利s,如果亏损只能亏损d,问这一年类十二个月盈利和亏损怎么分布才能让这一年的盈利最大,输出最大盈利,如果不能盈利或者不能符合要求输出“Deficit”。
这个题就是欺负你英语不好读不懂题意,其实还是很简单的只要每次猜中总结亏损都亏损在连续五个月中的后面几个月就好,这样可以让亏损在12个月中分布均匀,符合每五个月都亏损的情况,具体情况如下:
丑代码:
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
int Max,s,d;
bool flag;
void check_times(int k)
{
int y = 5-k;
if(k*d - y*s <= 0)
return ;
flag = true;
if(k == 1)
k = 2,y = 10;
else if(k == 2)
k = 4,y = 8;
else if(k == 3)
k = 6,y = 6;
else if(k == 4)
k = 9, y = 3;
else if(k == 5)
k = 12,y = 0;
int ans = y*s - k*d;
Max = max(ans,Max);
}
int main()
{
while(scanf("%d%d",&s,&d) != EOF)
{
Max = -10000000;
flag = false;
for(int i=1;i<=5;i++)
check_times(i);
if(!flag || Max < 0)
printf("Deficit\n");
else
printf("%d\n",Max);
}
return 0;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章