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 ...
随机推荐
- UVALive 6811 Irrigation Line(二分图最小点覆盖--匈牙利算法)
题意:求最少的线可以覆盖一个由0.1两种数字组成的图中所有的1. eg: 只需要两条线即可. 分析: 1.先为上述例子的行列标号 2.若图中数字为1,则代表该数字所在的行与列有关联. 例如第r1行第c ...
- 巧用Systemtap注入延迟模拟IO设备抖动
原创文章,转载请注明: 转载自系统技术非业余研究 本文链接地址: 巧用Systemtap注入延迟模拟IO设备抖动 当我们的IO密集型的应用怀疑设备的IO抖动,比如说一段时间的wait时间过长导致性能或 ...
- centos6.4下安装freetds使php支持mssql
centos版本:6.4 php版本5.3.17 没有安装之前的情况:nginx+php+mysql+FPM-FCGI 接下来安装步骤如下: 1.打开http://www.freetds.org/,进 ...
- wxPython Modal Dialog 模式对话框
<wxPython in Action>chap 9 笔记 1. Modal Dialog(模式对话框) A modal dialog blocks other widgets from ...
- Mooncake (排序+贪心)
Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...
- Node.js的process模块
process模块用来与当前进程互动,可以通过全局变量process访问,不必使用require命令加载.它是一个EventEmitter对象的实例. 属性 process对象提供一系列属性,用于返回 ...
- PHP内置函数
1 变量函数 a.is_xxx函数用来判断变量类型 is_int.is_integer.is_long,判断变量是否是整型 is_float.is_double.is_real ...
- Unity3d插件iTween的使用
iTween.cs 下载地址:http://pan.ceeger.com/viewfile.php?file_id=1830&file_key=0UJAymOJ 版本为2.0.43 一.iTw ...
- PHPCMS搭建wap手机网站
PHPCMS搭建PC端网站比较方便,但是在wap手机端方面却不怎么实用,而且自带的手机建站感觉不是很好,而且模版不好控制,现在对其进行修改,手机建站个人感觉比较方便 首先在phpcms/libs/fu ...
- java、js的编码、解码
如果在地址栏挂载参数,特别是包含中文,往往要进行编码,取值时再解码,以下是java和js中编码.解码的各自方法. java: @Test public void test3() throws Unsu ...