POJ 2586 Y2K Accounting Bug 贪心 难度:2
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 10537 | Accepted: 5264 |
Description
All what they remember is that MS Inc. posted a surplus or a deficit each month of 1999 and each month when MS Inc. posted surplus, the amount of surplus was s and each month when MS Inc. posted deficit, the deficit was d. They do not remember which or how many months posted surplus or deficit. MS Inc., unlike other companies, posts their earnings for each consecutive 5 months during a year. ACM knows that each of these 8 postings reported a deficit but they do not know how much. The chief accountant is almost sure that MS Inc. was about to post surplus for the entire year of 1999. Almost but not quite.
Write a program, which decides whether MS Inc. suffered a deficit during 1999, or if a surplus for 1999 was possible, what is the maximum amount of surplus that they can post.
Input
Output
Sample Input
59 237
375 743
200000 849694
2500000 8000000
Sample Output
116
28
300612
Deficit 题目意思:MS公司在1999年每个月有盈余有亏损,现在只知道盈余一定为s,亏损一定为d,并且该公司每连续五个月的总利润都是亏损(0-4,1-5,...7-11)(编号0-11),问如何取值(s,-d)在该条件下使得总利润最大,并且询问总利润是否可能为正数(盈利)
思路:贪心,如果统计需要次数最多的那个点容易造成断层,(比如第二组数据375 473,5 6 7 8都是被需要次数相同的,这个算法就不知道该先选择哪个,可能会先选择5,6,而4是一定要选的,选了4就不用选6了)
改变贪心思路,初始化全部选s,从头往尾扫,每个sum都必须变成-的为止,那么选择最右边的大于0,因为左边的要不就已经变成-的,或者使用次数没有右边多,直到sum变成负数为止
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int s,d;
int a[];
long long sum[];
int main()
{
while(scanf("%d%d",&s,&d)==){
for(int i=;i<;i++)a[i]=s;
for(int i=;i<;i++)sum[i]=*s;
for(int i=;i<;i++){
int t=;
while(sum[i]>=){
a[i+t]=-d;
for(int j=max(i+t-,);j<&&j<=i+t;j++){
sum[j]-=d+s;
}
t--;
}
}
long long ans=sum[]+sum[]+a[]+a[];
if(ans>=)printf("%I64d\n",ans);
else printf("Deficit\n");
}
return ;
}
POJ 2586 Y2K Accounting Bug 贪心 难度:2的更多相关文章
- poj 2586 Y2K Accounting Bug (贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8678 Accepted: 428 ...
- poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)
#include <iostream> using namespace std; /*248K 32MS*/ int main() { int s,d; while(cin>> ...
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- 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 (找规律)
Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...
随机推荐
- compile vi from source code
1.install ncurses library (vi depend on ncurses library) ./configure --prefix=/usr --with-termlib m ...
- POJ3436 ACM Computer Factory(最大流/Dinic)题解
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8944 Accepted: 3 ...
- 《EMCAScript6入门》读书笔记——22.Module的语法
- [异常记录-12]Web Deploy部署:未能连接到远程计算机,请确保在远程计算机上安装了 Web Deploy 并启动了所需的进程("Web Management Service")
Web Deploy 安装 请参考:图文详解远程部署ASP.NET MVC 5项目 如此安装后还不行, 可以在卸载后重新安装 Web Deploy 时,不要选那个经典还是典型的安装选项,选自定义安装 ...
- HDU 6121 Build a tree(完全K叉树)
http://acm.hdu.edu.cn/showproblem.php?pid=6121 题意:给你一颗完全K叉树,求出每棵子树的节点个数的异或和. 思路: 首先需要了解一些关于完全K叉树或满K叉 ...
- bugfree 安装配置(Ubuntu16.04 amd 64 Desktop)
上面是我使用的版本! 1.首先搭建 xampp 下载XAMPP:https://www.apachefriends.org/download.html 注意:下载低版本的,不然之后会找不到mysql ...
- HTML5-form表单
什么是表单? 01.获取用户的输入 ==>收集数据 02.将用户的输入发送到服务器 ==>与服务器进行交互 相关属性: action:我们收集完用户的信息之后,需要提交的服务器地址 ...
- Python day12部分内置函数的常见方法
#内置函数 print(abs(-1))#绝对值 ']))#判断list的真假,都真则真,有一个假也是假 print(any(''))#有一个真就真,全假则假 print(bin(3))#十进制转换二 ...
- spring boot开发 静态资源加载不出来
spring boot 1.5 版本之前 不拦截静态资源 springboot 2.x版本 拦截静态资源 private static final String[] CLASSPATH_RESOURC ...
- IIS8.5支持WCF
昨天写了个WCF例子,在我电脑上怎么发布都不成功,老是报错. 后来把这个例子放到其他人电脑上发布都没问题,这应该就是我IIS的问题了.我用的是win8.1的系统,IIS版本是8.5,IIS8.5默认是 ...