ZOJ1867 POJ2586 Y2K Accounting Bug
2012-02-16 19:26
330 查看
坑爹的贪心...
题目的大意是, 每个月要么盈利s, 要么亏损d.
且每五个月做一次这5个月的财政报表(1~5, 2~6...), 共8次报表均亏损.
问能否全年盈利, 能则给出最大值.
如果要保证全年盈利最大值, 则全年的盈利月必须最大, 同时要保证每连续5个月的总报表要亏损. 故我们可以有以下5总情况
SSSSDSSSSDSS
SSSDDSSSDDSS
SSDDDSSDDDSS
SDDDDSDDDDSD
DDDDDDDDDDDD
为什么要这么排列呢? 因为这样排列, 可以保证每5个月都是存在的亏损月都是固定的. 同时[1~5]月中, 把亏损月放到最后可以保证全年的亏损月是最少的. 例如在3中, 我们如果第2,3,4月亏损, 则全年的亏损月为7.
于是, 我们首先要判断五个月中亏损是否多于盈利, 再求出全年是否盈利, 盈利的话是多少.
题目的大意是, 每个月要么盈利s, 要么亏损d.
且每五个月做一次这5个月的财政报表(1~5, 2~6...), 共8次报表均亏损.
问能否全年盈利, 能则给出最大值.
如果要保证全年盈利最大值, 则全年的盈利月必须最大, 同时要保证每连续5个月的总报表要亏损. 故我们可以有以下5总情况
SSSSDSSSSDSS
SSSDDSSSDDSS
SSDDDSSDDDSS
SDDDDSDDDDSD
DDDDDDDDDDDD
为什么要这么排列呢? 因为这样排列, 可以保证每5个月都是存在的亏损月都是固定的. 同时[1~5]月中, 把亏损月放到最后可以保证全年的亏损月是最少的. 例如在3中, 我们如果第2,3,4月亏损, 则全年的亏损月为7.
于是, 我们首先要判断五个月中亏损是否多于盈利, 再求出全年是否盈利, 盈利的话是多少.
#ifdef _MSC_VER #define DEBUG #define _CRT_SECURE_NO_DEPRECATE #endif #include <fstream> #include <stdio.h> #include <iostream> #include <string.h> #include <string> #include <limits.h> #include <algorithm> #include <math.h> #include <numeric> #include <functional> #include <ctype.h> #define MAX 100010 using namespace std; int main(void) { #ifdef DEBUG freopen("../stdin.txt","r",stdin); freopen("../stdout.txt","w",stdout); #endif int s,d; while(~scanf("%d%d",&s,&d)) { int ans=-1; for(int i=1;i<=4;++i) if(i*d>s*(5-i)) { int mon=i*2+(i==4); ans=max(ans,(12-mon)*s-mon*d); } if(ans>0) printf("%d\n",ans); else printf("Deficit\n"); } return 0; }
相关文章推荐
- POJ2586 Y2K Accounting Bug (簡單貪心問題)
- POJ2586 Y2K Accounting Bug(贪心)
- POJ2586:Y2K Accounting Bug
- Y2K Accounting Bug(poj2586)
- POJ2586,Y2K Accounting Bug,简单是简单,无法理解此类叙述的思维
- poj2586 Y2K Accounting Bug 贪心
- POJ2586 Y2K Accounting Bug
- Y2K Accounting Bug(poj2586,枚举)
- POJ2586--Y2K Accounting Bug(贪心)
- POJ2586-Y2K Accounting Bug
- poj2586 Y2K Accounting Bug 贪心
- poj2586 Y2K Accounting Bug 贪心
- poj2586--Y2K Accounting Bug
- poj2586 Y2K Accounting Bug
- poj2586 Y2K Accounting Bug(贪心)
- 貪心::poj1328 radar installation && poj2109 Power of Cryptography && poj2586 Y2K Accounting Bug
- poj2586 Y2K Accounting Bug(贪心)
- POJ2586 Y2K Accounting Bug(贪心)
- Y2K Accounting Bug poj
- Y2K Accounting Bug