標籤:des style blog color 使用 os strong io
Y2K Accounting Bug
| Time Limit: 1000MS |
|
Memory Limit: 65536K |
| Total Submissions: 10316 |
|
Accepted: 5136 |
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
連續五個月要虧損,這是邊界條件,總共加起來要是盈利。這樣的話,前五個月一定要把虧損的放在後面,這樣12個月裡,盈利的月就更多了。
eg: 1 2 3 4 5 6 7 8 9 10 11 12
s s s d d s s s d d s s 8s
d d s s s d d s s s d d 6s
這裡的貪心就是盡量讓12個月盈利最大,這樣就要讓虧損的月重複使用。
我是直接用枚舉。反正只有4種情況,再判斷(K*s-M*d)<0
1 #include<cstdio> 2 #include<string.h> 3 using namespace std; 4 int main() 5 { 6 int s,d; 7 int ok=1; 8 int x,y,z,e; 9 while(scanf("%d%d",&s,&d)!=EOF)10 {11 x=s*10-2*d;12 y=8*s-4*d;13 z=6*s-6*d;14 e=3*s-9*d;15 if(x>0&&(4*s-d)<0)16 printf("%d\n",x);17 else if(y>0&&(3*s-2*d)<0)18 printf("%d\n",y);19 else if(z>0&&(2*s-3*d)<0)20 printf("%d\n",z);21 else if(e>0&&(1*s-4*d)<0)22 printf("%d\n",e);23 else printf("Deficit\n");24 }25 return 0;26 }