题目地址: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. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  2. Resources in Visual Tracking(转载)

    这位博主总结了比较新的tracking方面的资源:http://blog.csdn.net/minstyrain/article/details/38640541 http://xilinx.eetr ...

  3. Python win7下 django-admin.py startproject mysite命令没有创建mysite?

    解决方案 解决:这个命令在XP下正常(我没试过),我用的win7,无法创建.这属于django的一个bug. 方法是:修改注册表中 HKEY_CLASSES_ROOT/Applications/pyt ...

  4. 查看一些特定sql需求的书写

    user表,5个人abcde,  content表10篇文章,一个人对应两篇文章,有 time字段,查询出五个人的最新文章. select a.id,a.SName,a.ClsNo,a.Scorefr ...

  5. recv和send函数

    转自  http://www.cnblogs.com/blankqdb/archive/2012/08/30/2663859.html 1. send解析 sockfd:指定发送端套接字描述符. bu ...

  6. bootbox显示中文的按钮

    $("selector").on('click',function(){ bootbox.confirm({ title : "请确认", buttons: { ...

  7. iOS7总显示状态栏的解决方法

    转载http://blog.csdn.net/langresser_king/article/details/18351021 2014年2月份开始,苹果需求开发者必须使用xcode5开发游戏和应用, ...

  8. 【python】2048

    来源:https://www.shiyanlou.com/courses/368 实验楼的2048程序,在linux下可实现通过终端游戏. 主要学习的知识点: 1.状态机函数实现,用字典将状态和函数相 ...

  9. OSG addEventHandler W键 L键 F键

    // add the state manipulator    viewer->addEventHandler( new osgGA::StateSetManipulator(viewer-&g ...

  10. 解决win7访问不了局域网共享文件

    1.确认链接 2.确认服务TCP/IP NetBIOS Helper 启动 3.secpol.msc 确认 本地策略->用户权限分配 如图