贪心 POJ 2586 Y2K Accounting Bug
题目地址: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的更多相关文章
- poj 2586 Y2K Accounting Bug (贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8678 Accepted: 428 ...
- POJ 2586 Y2K Accounting Bug 贪心 难度:2
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10537 Accepted: 52 ...
- poj 2586 Y2K Accounting Bug
http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...
- POJ 2586 Y2K Accounting Bug(枚举洪水问题)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10674 Accepted: 53 ...
- POJ 2586 Y2K Accounting Bug(枚举大水题)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10674 Accepted: 53 ...
- [POJ 2586] Y2K Accounting Bug (贪心)
题目链接:http://poj.org/problem?id=2586 题目大意:(真难读懂啊)给你两个数,s,d,意思是MS公司每个月可能赚钱,也可能赔钱,如果赚钱的话,就是赚s元,如果赔钱的话,就 ...
- 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) ...
- poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)
#include <iostream> using namespace std; /*248K 32MS*/ int main() { int s,d; while(cin>> ...
- POJ - 2586 Y2K Accounting Bug (找规律)
Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...
随机推荐
- 自定义 array_map() 对应的递归函数 array_map_recursive()
array_walk 有个原生递归函数 array_walk_recursive($arr, 'function', 'words'),但是 array_map 却没有对应的递归函数 array_ma ...
- SGU 180 Inversions(离散化 + 线段树求逆序对)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=180 解题报告:一个裸的求逆序对的题,离散化+线段树,也可以用离散化+树状数组.因为 ...
- vim常用指令及快捷键(持续更新)
(这些文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 发现了个非常赞的网站 http://openvim.com/ 以下很多操作都是安装好vund ...
- petri网学习心得
本文转载自duxw,如给您带来不便之处,请联系博主. 1.Petri网书籍:<petri网导论>,吴哲辉 非常适合初学者.概念清晰,容易理解. 2.工作流书籍:<Workflow M ...
- JDK 工具列表
jar — 一个创建和管理 jar 文件的工具. java — Java 应用启动器.在这篇文章里,开发和部署都是用的这个启动器. javac — Java 编译器. javadoc — API 文档 ...
- iOS设备通知中心精品推荐消息删除
如要彻底解决这个问题可以通过手机连接PC端91助手—功能大全—文件管理,进入/Library/MobileSubstrate/DynamicLibraries 文件夹,把AppSafety开头的文件都 ...
- MySQL主备停机步骤与注意事项
双十一马上到了,一堆的事情,今天登录mysql数据库服务器的时候突然发现服务器时间戳不对,比北京时间快了几分钟,我的天...随后检查了其他的几台数据库服务器发现同样都存在不同的偏差,最小的比北京时间快 ...
- makefile_1(初识make)
Makefile有三个非常有用的变量.分别是$@,$^,$<代表的意义分别是: $@--目标文件,$^--所有的依赖文件,$<--第一个依赖文件. LIBS = -lmCFLAGS = - ...
- php编译报错 configure: error: Please reinstall the BZip2 distribution
yum install -y bzip2 bzip2-devel
- Js 正则表达式特殊字符含义
字符 匹配 \o null \t 制表符 \n 换行符 \v 垂直制表符 \f 换页符 \r 回车符 \xnn 由十六进制nn指定的拉丁字符 ...