POJ 2586 Y2K Accounting Bug(贪心)
2012-11-14 16:14
441 查看
题目链接
题意真纠结啊。神马盈余,负债的。。。差不多看懂样例了,是反正一年12个月可能赚钱,可能赔钱。。。
题意:1-5月, 2-6月....8-12月,做8次统计,在统计内的5个月,整体上都是赔钱的。求这一年可能盈利多少。
第一想法枚举,2^12次方,然后TLE,换了乱搞办法,和暴力的对拍,讨论5个月,盈利最多的情况下,依旧赔钱,乱搞一下就行。
题意真纠结啊。神马盈余,负债的。。。差不多看懂样例了,是反正一年12个月可能赚钱,可能赔钱。。。
题意:1-5月, 2-6月....8-12月,做8次统计,在统计内的5个月,整体上都是赔钱的。求这一年可能盈利多少。
第一想法枚举,2^12次方,然后TLE,换了乱搞办法,和暴力的对拍,讨论5个月,盈利最多的情况下,依旧赔钱,乱搞一下就行。
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N -100000000 int main() { int i,j,s,d,ans,k,sum; int o[13]; while(scanf("%d%d",&s,&d)!=EOF) { ans = N; /*for(i = 1;i < (1<<12);i ++)//暴力的方法 { memset(o,0,sizeof(o)); for(j = 0;j <= 11;j ++) { if(i&(1<<j)) o[j+1] = 1; } for(j = 1;j <= 8;j ++) { sum = 0; for(k = j;k <= j+4;k ++) { if(o[k]) sum += s; else sum -= d; } if(sum >= 0) break; } if(j == 9) { sum = 0; for(k = 1;k <= 12;k ++) { if(o[k]) sum += s; else sum -= d; } if(ans < sum&&sum > 0) ans = sum; } } */ for(i = 1;i <= 4;i ++) { if(i == 1) { if(4*s-d < 0) { sum = 10*s - 2*d; if(ans < sum&&sum > 0) ans = sum; } } else if(i == 2) { if(3*s-2*d < 0) { sum = 8*s - 4*d; if(ans < sum&&sum > 0) ans = sum; } } else if(i == 3) { if(2*s-3*d < 0) { sum = 6*s - 6*d; if(ans < sum&&sum > 0) ans = sum; } } else if(i == 4) { if(s-4*d < 0) { sum = 3*s - 9*d; if(ans < sum&&sum > 0) ans = sum; } } } if(ans == N) printf("Deficit\n"); else printf("%d\n",ans); } return 0; }
相关文章推荐
- Y2K Accounting Bug POJ - 2586 (贪心+枚举)
- poj 贪心相关之 Y2K Accounting Bug2586
- poj 2586 Y2K Accounting Bug (贪心)
- poj 2586 Y2K Accounting Bug——我感觉是枚举(分类是贪心)
- poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)
- POJ 2586 Y2K Accounting Bug 贪心 难度:2
- POJ 2586 Y2K Accounting Bug (贪心)
- POJ 2586 Y2K Accounting Bug(贪心)
- POJ Y2K Accounting Bug 2586(贪心)
- 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(贪心)
- POJ2586 Y2K Accounting Bug(贪心)
- 【贪心】POJ-2586 Y2K Accounting Bug
- POJ 2586 Y2K Accounting Bug 贪心