poj 2586 Y2K Accounting Bug(贪心)
2017-09-09 10:50
369 查看
Y2K Accounting Bug
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 15926 Accepted: 7984
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
题意:盈利s,赤字d,要求每五个月总额是亏损的,求12个月的盈利最大值,没有盈利输出“Deficit”。
贪心,使得每五个月之中的亏损尽可能小。
#include <iostream> #include <cstdio> using namespace std; int a[6]; int main() { //freopen( "in.txt", "r", stdin ); int s, d, sum, flg; while( scanf( "%d%d", &s, &d ) != EOF ){///surplus deficit for( int i = 1 ; i <= 5 ; i ++ ){ a[i] = s; } while( 1 ){ sum = flg = 0; for( int i = 5 ; i >= 1 ; i -- ){ if( !flg && a[i] > 0 ){/// flg = 1; a[i] = 0-d; } sum += a[i]; } if( a[1] < 0 || sum <= 0 ) break; } sum = sum * 2 + a[1] + a[2];///是a[1],a[2],不是2*s if( sum > 0 ) cout<<sum<<endl; else cout<<"Deficit"<<endl; } return 0; }
相关文章推荐
- poj 2586 Y2K Accounting Bug (贪心)
- POJ 2586 Y2K Accounting Bug(贪心)
- POJ_2586 Y2K Accounting Bug(贪心)
- Y2K Accounting Bug POJ - 2586 (贪心+枚举)
- poj2586——Y2K Accounting Bug(贪心)
- Y2K Accounting Bug POJ - 2586 (贪心+枚举)
- POJ 2586 Y2K Accounting Bug贪心
- POJ训练计划2586_Y2K Accounting Bug(贪心)
- poj 2586 Y2K Accounting Bug——我感觉是枚举(分类是贪心)
- POJ 2586-Y2K Accounting Bug(贪心)
- Y2K Accounting Bug POJ - 2586 (贪心+枚举)
- POJ 2586 Y2K Accounting Bug 贪心 难度:2
- POJ2586 Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug(贪心+枚举)
- POJ 2586 Y2K Accounting Bug 贪心
- Y2K Accounting Bug POJ - 2586 (贪心+枚举)
- POJ 2586 Y2K Accounting Bug 贪心
- poj 贪心相关之 Y2K Accounting Bug2586
- Y2K Accounting Bug POJ - 2586 (贪心+枚举)
- poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)