pku 2586 Y2K Accounting Bug 第一周训练——贪心
2012-02-24 21:21
239 查看
http://poj.org/problem?id=2586
刚开始看了很长时间都没看懂题意,最后还是看了discuss里面讲的才懂了。开始还把连续五个月都会抱亏的题意理解错了。我理解成1 - 5 6 - 10 11-12 了。。心想怎么会一年8次呢。最后才看到原来是1-5 2-6 3 -7 4 - 8 5 -9 6 -10 7 -11 8 -12这8次报表时都是亏空的。而每个月可能盈利,也可能亏空所以这样就会导致全年盈利的情况了。
这题的贪心在于,这8次中,出了第一次每一次都会和上一次重复利用连续的四个月的盈亏情况,所以我们贪心的让他们共用亏空,这样就会使盈利的月份增多,所以能够获得最大利润。
View Code
刚开始看了很长时间都没看懂题意,最后还是看了discuss里面讲的才懂了。开始还把连续五个月都会抱亏的题意理解错了。我理解成1 - 5 6 - 10 11-12 了。。心想怎么会一年8次呢。最后才看到原来是1-5 2-6 3 -7 4 - 8 5 -9 6 -10 7 -11 8 -12这8次报表时都是亏空的。而每个月可能盈利,也可能亏空所以这样就会导致全年盈利的情况了。
这题的贪心在于,这8次中,出了第一次每一次都会和上一次重复利用连续的四个月的盈亏情况,所以我们贪心的让他们共用亏空,这样就会使盈利的月份增多,所以能够获得最大利润。
View Code
#include <iostream> #include <cmath> #include <cstdio> #include <cstring> #define maxn 13 using namespace std; int main() { int s,d; while (~scanf("%d%d",&s,&d)) { int sum = -1; if (4*s < d) sum = 10*s - 2*d; else if (3*s < 2*d) sum = 8*s - 4*d; else if (2*s < 3*d) sum = 6*s - d*6; else if (s < 4*d) sum = 3*s - 9*d; if (sum > 0) { printf("%d\n",sum); } else printf("Deficit\n"); } return 0; }
相关文章推荐
- POJ训练计划2586_Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug (贪心)
- POJ2586——贪心——Y2K Accounting Bug
- Y2K Accounting Bug POJ - 2586 (贪心+枚举)
- 2586 Y2K Accounting Bug 贪心 枚举
- poj 2586 Y2K Accounting Bug 贪心
- Y2K Accounting Bug POJ - 2586 (贪心+枚举)
- Y2K Accounting Bug POJ - 2586 (贪心+枚举)
- poj2586——Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug 贪心
- poj 2586 Y2K Accounting Bug【贪心】【刷题计划】
- poj2586 Y2K Accounting Bug(贪心,java)
- POJ 2586 Y2K Accounting Bug(贪心)
- poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)
- [POJ 2586] Y2K Accounting Bug (贪心)
- POJ 2586 Y2K Accounting Bug (贪心)
- POJ 2586 Y2K Accounting Bug贪心
- poj 贪心相关之 Y2K Accounting Bug2586
- POJ 2586:Y2K Accounting Bug(贪心)