Y2K Accounting Bug
题目:
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.
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
//感觉这道题考的是阅读理解啊~题目超难懂,看半天也没个所以然........= =
/*
题目大意:
每个月固定盈利和固定亏损分别为s和d,公司每连续5个月进行一次统计,结果都是亏损,问公司是否能盈利?能就输出盈利,否就输出Deficit。
*/
那么总共就只有5种情况:
1.每次有1个月亏损,即0<4s<d→0<s<d/4,为SSSSDSSSSDSS;
2.每次有2个月亏损,即3s<2d→s<2d/3,为SSSDDSSSDDSS;
3.每次有3个月亏损,即2s<3d→s<3d/2,为SSDDDSSDDDSS;
4.每次有4个月亏损,即s<4d,为SDDDDSDDDDSD;
5.每次有5个月亏损,即s>=4d,为DDDDDDDDDDDD;
代码如下:
1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 double s,d; 6 while(cin>>s>>d) 7 { 8 double n; 9 if(s>=0 && s<d/4) n=10*s-2*d; 10 if(s>=d/4 && s<2*d/3) n=8*s-4*d; 11 if(s>=2*d/3 && s<3*d/2) n=6*s-6*d; 12 if(s>=3*d/2 && s<4*d) n=3*s-9*d; 13 if(s<0 || (s==0 && d>=0) || s>=4*d) n=-1; 14 if(n>=0) cout<<n<<endl; 15 else cout<<"Deficit\n"; 16 } 17 return 0; 18 }