POJ2586——Y2K Accounting Bug
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 题目大意:微软公司的12个月的盈利情况,已知每月若盈利,则固定为s元;若亏损,则固定为d元。在保证每个连续的五个月都是亏损的情况下,判断是否可以全年盈利,若盈利,输出最大盈利额,反之,输出Deficit
解题思路:贪心的思想,保证每个连续5个月亏损最少即可。
eg: s=59 d=237 那么连续五个月中 4个月盈利,一个月亏损时连续亏损最小,为-1;
假设[1,5]表示一月到五月的总亏损,保证[1,5]=-1,那么[2,6]要想同样最小 六月的盈亏情况应与一月相同。
同理:七月与二月相同,八月与三月相同。显然六到十月份的盈亏状态应同一月到五月的。
显然:十一月与十二月 分别对应 一月和二月。
这里设盈利为1,亏损为0 [1-5]=11110||10111||11011.... 要想最大盈利,要保证最后两个月尽量盈利,及保证一月二月最大盈利,故前五个月应保证盈利月在前。
Code:
#include<stdio.h>
int main()
{
int s,d,sum,cnt;
while (scanf("%d %d",&s,&d)!=EOF)
{
sum=s*;
cnt=;
while (sum>=)
{
sum-=d+s;
cnt++;
}
sum=(s*(-cnt)-cnt*d)*;//前十个月的总盈亏
if (cnt==) {sum+=s;sum-=d;}//判断最后两月的盈亏状况
else if (cnt==) sum-=*d;
else sum+=*s;
if (sum>) printf("%d\n",sum);//sum<0 说明亏损
else printf("Deficit\n");
}
return ;
}
POJ2586——Y2K Accounting Bug的更多相关文章
- [POJ2586]Y2K Accounting Bug
[POJ2586]Y2K Accounting Bug 试题描述 Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...
- poj2586 Y2K Accounting Bug(贪心)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=2586 ------ ...
- POJ2586 Y2K Accounting Bug 解题报告
Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vi ...
- POJ-2586 Y2K Accounting Bug贪心,区间盈利
题目链接: https://vjudge.net/problem/POJ-2586 题目大意: MS公司(我猜是微软)遇到了千年虫的问题,导致数据大量数据丢失.比如财务报表.现在知道这个奇特的公司每个 ...
- POJ2586 Y2K Accounting Bug(贪心)
题目链接. 题目大意: 题目相当晦涩难懂啊. 一年的12个月,每5个月统计一次,如从1~5,2~6,3~7,...,8~12共统计了8次,已知每次都deficit,问这一年有没有盈利的可能. 一个月s ...
- poj2586 Y2K Accounting Bug —— 枚举
链接:http://poj.org/problem?id=2586 题意:大意是一个公司在12个月中,或固定盈余s,或固定亏损d.但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(和 ...
- Y2K Accounting Bug(贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10945 Accepted: 54 ...
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- Y2K Accounting Bug 分类: POJ 2015-06-16 16:55 14人阅读 评论(0) 收藏
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11222 Accepted: 56 ...
随机推荐
- ssh 私匙登录, 文件rswrst权限
skill -KILL -u user1 //注销用户 ssh 免密码登录 http://flysnowxf.iteye.com/blog/1567570 (说是防火墙的问题) http://fly ...
- Centos7下安装netstat
刚安装centos7发想没有查看端口的命令 netstat yum install net-tools
- MYSQL数据库主主同步实战
MYSQL支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维护日志文件的一个索引以跟踪日志循环.当一个从服务器连接到主服务 ...
- laravel--上传
1.视图里面 2.控制器里面 //收集表单提交数据 $input = $request->all(); //查看是否有图片提交上来 if ($request->hasFile('title ...
- php学习日志(3)-echo&print
在php中,结果输出一共有两种方式:echo和print,下面将对两种方式做一个比较. echo与print的区别: echo print 连续输出字符串 能连续输出多个字符串 只能输出一个字符串 ...
- 3.12php
这是我的第一个博客 纪念一下 反正都是自己看 第一个问题 出现错误 当图片超过1M时就可能出现以下错误 当然这个也跟你php.ini设置有关 如果你php设置里 memory_limit 16M ...
- Demo学习: Closable Tabs
Closable Tabs 给tab页添加关闭按钮,设置UniTabSheet.Closable = True这样在tab页的右上角就会出现关闭图标,点击可以关闭当前tab页面: 1. 直接关闭,完成 ...
- C#...何时需要重写ToString()方法?
一般类型,都是继承自System.Object类,默认情况下,object类的ToString方法会返回当前类的类型的字符串表达形式.但也有例外!! DateTime,它就重写ToString方法,D ...
- 【BZOJ3262】 陌上花开
Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当 ...
- ORA-01034:oracle不可用 的解决方法
晚上打开SQLPlus输入用户名和密码老是登不了,出现如上一行代码 "ORA-01034:ORACLE不可用"的错误 解决思路: 1.检查服务是否启动, 2.如果已经启动,说明数据 ...