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 ...
随机推荐
- 手动从浏览器中获取 cookie
以 chrome 浏览器为例 1) 浏览器登陆人人网并打开一个人人网页面 2)打开 开发者工具,快捷键 Ctrl + Shift + I(大写 i) 3)切换到 console 页,输入 docume ...
- HTML5之缓存
----- 缓存文件 - 使用UTF-8编码- 以Cache Manifest 开头- 三个基本部分 CACHE MANIFESTmenu.htmlmenu.js# login requires ne ...
- offset() position() scrollTop() scrollLeft()
(1)offset:获取当前元素相对于文档的高度.只对可见元素有效. 不管该元素如何定位,也不管其父元素如何定位,都是获取的该元素相对于当前视口的偏移 (2) position:获取元素相对于最近的一 ...
- C# 与C++的数据转换
一.类型转化 下面重点罗列下常用的类型转化. C++类型 C#类型 备注说明 Int Int16.Int32 没有悬念,直接转化 Uint UInt16.Uint32.int 在程序中,不太清楚是,就 ...
- github项目filter_firewall说明
本文编写的目的: 本文是对上传到github上的项目进行说明.github链接:filter_firewall有任何意见或者建议可以Email:18277973721@sina.cn 项目介绍: 包过 ...
- T-SQL实例 函数结果设置为列别名
本文分享一个T-SQL的例子,将自定义函数的结果作为别名列,是个不错的应用实例,有兴趣的朋友研究下. T-SQL实例,学习下将函数结果作为别名列的方法. 代码: view source print? ...
- http返回状态代码及含义
“100″ : Continue(继续) 初始的请求已经接受,客户应当继续发送请求的其余部分.(HTTP 1.1新) “101″ : Switching Protocols(切换协议) 请求者已要求服 ...
- Mac下使用sublime text 2开发Python
入门虽易, 熟练不易, 且行且珍惜 简介:这只是简单介绍一个好的文本工具sublime text的使用,如果要获得详细的教程可以去看这本书<Sublime Productivity>和一些 ...
- 由底层和逻辑说开去——c++之类与对象的深入剖析
类是什么,对象是什么, 这两个问题在各个c++书里面都以一种抽象的描述方式,给了我们近乎完美的答案,然后我好像就知道什么是类什么是对象了,但是当扪心自问,类在哪儿,对象在哪儿,成员方法在哪儿,成员变 ...
- PAT乙级真题1004. 成绩排名 (20)(解题)
题目: 读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式:每个测试输入包含1个测试用例,格式为 第1行:正整数n 第2行:第1个学生的姓名 学号 成绩 第3行:第 ...