题目地址:http://poj.org/problem?id=2586

 /*
题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D。
公司每五个月进行一次统计,全年共统计8次(1-5、2-6、3-7、4-8、5-9、6-10、7-11、8-12),
已知这8次统计的结果全部是亏空(盈利-亏空<0)。题目给出S和D,判断全年是否能盈利,
如果能则求出盈利的最大值,如果不能盈利则输出Deficit
贪心 or 枚举
1. 贪心抓住亏损的月尽量在5个月的后面,这样可以被下一次利用,从而获取最大值
2. 可以枚举是因为可能的情况少
详细解释:http://blog.csdn.net/lyy289065406/article/details/6642603
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
using namespace std; const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
int used[]; void work(int s, int d)
{
int sum = ; int cnt; int k; cnt = ;
while (s * (cnt) - d * ( - cnt) > && cnt > ) cnt--;
k = - cnt;
sum += s * ( - k) - d * k;
for (int i=; i>= && k--; --i) used[i] = ; for (int i=; i<=; ++i)
{
int n = ;
for (int j=i; j<=+i-; ++j)
{
if (used[j]) n++;
}
int tmp = ;
tmp += s * ( - n) - d * n;
if (tmp < && tmp + s < ) sum += s;
else
{
sum -= d; used[i+] = ;
}
} (sum >= ) ? printf ("%d\n", sum) : puts ("Deficit");
} int main(void) //POJ 2586 Y2K Accounting Bug
{
//freopen ("E.in", "r", stdin); int s, d;
while (~scanf ("%d%d", &s, &d))
{
memset (used, , sizeof (used));
work (s, d);
} return ;
} /*
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; int main(void)
{
//freopen ("E.in", "r", stdin); int s, d;
while (~scanf ("%d%d", &s, &d))
{
int ans = 0;
if (4 * s - d < 0)
{
ans = 10 * s - 2 * d;
}
else if (3 * s - 2 * d < 0)
{
ans = 8 * s - 4 * d;
}
else if (2 * s - 3 * d < 0)
{
ans = 6 * s - 6 * d;
}
else if (1 * s - 4 * d < 0)
{
ans = 3 * s - 9 * d;
}
else ans = -1;
if (ans > 0) printf ("%d\n", ans);
else puts ("Deficit");
} return 0;
}
*/

贪心 POJ 2586 Y2K Accounting Bug的更多相关文章

  1. poj 2586 Y2K Accounting Bug (贪心)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8678   Accepted: 428 ...

  2. POJ 2586 Y2K Accounting Bug 贪心 难度:2

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10537   Accepted: 52 ...

  3. poj 2586 Y2K Accounting Bug

    http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...

  4. POJ 2586 Y2K Accounting Bug(枚举洪水问题)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

  5. POJ 2586 Y2K Accounting Bug(枚举大水题)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

  6. [POJ 2586] Y2K Accounting Bug (贪心)

    题目链接:http://poj.org/problem?id=2586 题目大意:(真难读懂啊)给你两个数,s,d,意思是MS公司每个月可能赚钱,也可能赔钱,如果赚钱的话,就是赚s元,如果赔钱的话,就 ...

  7. POJ 2586 Y2K Accounting Bug(贪心)

    题目连接:http://poj.org/problem?id=2586 题意:次(1-5.2-6.3-7.4-8.5-9.6-10.7-11.8-12),次统计的结果全部是亏空(盈利-亏空<0) ...

  8. poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)

    #include <iostream> using namespace std; /*248K 32MS*/ int main() { int s,d; while(cin>> ...

  9. POJ - 2586 Y2K Accounting Bug (找规律)

    Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...

随机推荐

  1. C语言课程2——我们交流的工具:Coding.net

    各位同学,大家好,在我们本学期既有老师的课堂授课,同样也有我与你们在线的辅导:那么问题来了,我与你们之间是通过何种方式进行交流,比如你的代码我怎么修改,怎样看到修改了哪些地方,我对你们的代码怎样批注, ...

  2. JS匿名函数的理解

    js匿名函数的代码如下:(function(){ // 这里忽略jQuery 所有实现 })(); 半年前初次接触jQuery 的时候,我也像其他人一样很兴奋地想看看源码是什么样的.然而,在看到源码的 ...

  3. winform 添加“设置文件”

    添加配置文件 ·右击服务项目---添加新项---设置文件:----确定 ·把Settings1.settings,拖到properties里,双击Settings1.settings: 名称:是自己定 ...

  4. 解决kettle配置文件中的中文乱码

    在日常开发中有时候配置文件会出现中文(如config.properties 里有中文),为了避免出现乱码,因而要转成unicode编码. 1.在设置变量的javascript(转换中的JavaScri ...

  5. iOS 用CALayer实现动画

    与动画有关的几个类的继承关系 涉及到动画的类主要有6个,看一下它们的基本用途: 1. CAAnimation  动画基类 2. CAAnimationGroup 组合多个动画 3. CAPropert ...

  6. Mysql sql查询性能侦查

    Mysql 服务性能优化配置:http://5434718.blog.51cto.com/5424718/1207526[该文章很好] Sql查询性能优化 对Sql进行优化,肯定是该Sql运行未能达到 ...

  7. Quartus 软件的使用之PLL的使用

    练习使用Altera FPGA 内的 PLL IP核: 思路:将clk_50M倍频到clk_100M,然后观察100M时钟. 1.生成PLL的核例化文件,然后调用. 点击NEXT之后,等一会会跳出如下 ...

  8. 现在不能使用foxmail同步qq记事本功能,可能是对字数的大小有限制

    那么在经过了两个星期的时间完成的主要功能就是幻灯片和站点管理,在之后还有更多的任务要做,本来从时间的安排上不太合理,在这个月底要基本完成,主要是其他的组员也有比较重的任务,那么就是需要随时有一个状态, ...

  9. wp8 --未找到与约束ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryService...匹配的导出

    今天打算用VisualStudio2012做一个js效果页面测试的时候,打开VS2012新建项目,但是并没有像之前那样顺利的创建页面,而是弹出了一个错误窗口. 我的系统是win8专业版 64位 ,同时 ...

  10. 对学长所谓“改变世界的游戏”《shield star》的运行感想-毛宇部分(完整版本请参考团队博客)

    对于学长项目<shield star>的思考和看法: Ryan Mao ((毛宇)  110616-11061171 试用了一下学长黄杨等人开发的<shield star>游戏 ...