poj2586 Y2K Accounting Bug 贪心
来源:互联网 发布:图片后期制作软件 编辑:程序博客网 时间:2024/05/02 02:07
///2014.3.3///poj2586/** *题目大意是一个公司在12个月中,或固定盈余s,或固定亏损d. *但记不得哪些月盈余,哪些月亏损, *只能记得连续5个月的代数和总是亏损(<0为亏损), *问全年是否可能盈利,若可能,输出可能最大盈利金额, *否则输出“Deficit”. *思路: *题意说连续的五个月的代数总和一定是亏损,则可以根据 s 和 d *求出连续的五个月至少有 dInFive 个月是亏损的 *例如连续的五个月至少有 2 个月亏损(dInFive=2) *则,1-5月中4月和5月设为亏损,接着检查下一个连续的五个月(2-6月) *从尾部开始将其设成一共有2个月亏损 *最后可以求出12个月中一共至少要有几个月亏损 */#include <cstdio>int s,d;int dInFive; ///表示在连续五个月中最少有几个月份亏损int month[6] = {0,2,4,6,9,12}; ///month[i]表示 i 为 dInFive时,12个月中的最少亏损月份数,笔算即可求出int S;void init( ){ for(dInFive=0 ; dInFive*d<(5-dInFive)*s ; dInFive++); ///求出dInFive S = s*(12-month[dInFive]) - d*month[dInFive];}int main( ){// freopen("in","r",stdin);// freopen("out","w",stdout); while( scanf("%d%d",&s,&d)!=EOF ){ init(); if( S>0 ) printf("%d\n",S); else printf("Deficit\n"); } return 0;}
0 0
- 【贪心】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(贪心)
- POJ2586《Y2K Accounting Bug》方法:贪心
- poj2586 Y2K Accounting Bug(贪心)
- POJ2586--Y2K Accounting Bug(贪心)
- poj2586 Y2K Accounting Bug(贪心,java)
- 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
- Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastor
- poj2109 Power of Cryptography
- linux系统时间
- VLC的object标签页可以支持火狐
- 有青春的细节
- poj2586 Y2K Accounting Bug 贪心
- android相对布局
- 制作ubuntu server 12.04安装U盘
- Intellij IDEA常用配置详解
- TextView属性
- Linux中断函数应避免使用不可重入函数
- poj3295 Tautology
- C#预处理器指令的用法
- 【记录】安全相册--发布到应用商店的第一个应用