poj 2586 Y2K Accounting Bug (贪心)
来源:互联网 发布:淘宝详情制作软件 编辑:程序博客网 时间:2024/05/02 04:27
题目链接:http://poj.org/problem?id=2586
这个题最麻烦的就是读题了,这么长的题目,读了好久,大意就是说一个公司,每个月都只能盈利s或者亏损d,每5个月统计账目,每次都是亏损,但一年可以是亏损也可以盈利,如果可以盈利,求最大值,不能则打印“Deficit”。
开始的时候我想的是每五个月一统计,就先求前五个月,然后依次求第六,第七个月等等。
其中前五个月先让前n个月盈利,后n - 5个月亏损,然后递推。
发现好麻烦,而且2 - 6月考虑时还要讨论前面5个月甚至要改变前5个月的值。
SJ,提出来,就这12个月,加上刚才的贪心策略,总共就5种情况,遍历就好啦,每个情况试试,结果就出来了。
代码如下:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>int main(){ int s,d; while (~scanf ("%d%d",&s,&d)) { int i; for (i = 0;i < 5;i++) if ((i + 1) * s - (4 - i) * d >= 0) break; int ans; if (i >= 2) ans = (i * s - (5 - i) * d) * 2 + 2 * s; else if (i == 1) ans = s * 3 - 9 * d; else ans = -12 * d; if (ans < 0) puts ("Deficit"); else printf ("%d\n",ans); } return 0;}
0 0
- 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 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--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 2586 Y2K Accounting Bug 简单贪心
- POJ 2586 Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug (贪心)
- centos 6.5 DNS服务器配置
- oj类模板
- 动态规划详解
- 【算法拾遗】子数组的最大乘积
- 如何在6572的code下面新建一个工程
- poj 2586 Y2K Accounting Bug (贪心)
- QT_PC学习_GUI程序设计入门_窗口
- andriod 应用图标的问题
- DFS序——解决一类树上数据结构问题的方法
- VMware无法运行,重新安装提示“您可能没有合适的权限访问这个项目”的解决办法
- POJ训练计划2524_Ubiquitous Religions(并查集)
- crm2011QueryByAttribute的事例
- js获取文本编译器CKEditor的值
- 舍不得让你输