Problem M

时间:2023-03-09 05:10:21
Problem M
Problem 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
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;让你求最大盈利数;
解题思路:可以这么想先求前5个月的在亏钱的前提下,盈利月数最多的情况,这样6-10月结果可以和1-5月一样,11,12月的,要是5个月中盈利月数大约等于2,那么11,12月全盈利就行了,如果不是的话,就先把盈利的月数加上;
感悟:是不是得训练看题了......这个比英语阅读理解还烦.....
代码(G++ 0
MS)
#include

   #include

using namespace std;

   int main()

   {

   
//freopen("in.txt", "r", stdin);

    int
s=0,d=0,money=0,month=0;

   
while(~scanf("%d%d",&s,&d))

    {

       
money=month=0;

       
for(int i=1;i<=6;i++)

           
if(s*i>=d*(5-i))

           
{

                
month=i-1;

                
break;

           
}//算出来五个月亏钱时最少亏钱月数

       
//printf("month=%d\n",month);

       
switch(month)

       
{

           
case 0:money=-12*d;break;

           
case 1:money=3*s-9*d;break;

           
case 2:money=6*s-6*d;break;

           
case 3:money=8*s-4*d;break;

           
case 4:money=10*s-2*d;break;

       
}

       
if(money<0)

           
printf("Deficit\n");

       
else

           
printf("%d\n",money);

    }

    return
0;

}