Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 11271   Accepted: 5672

Description

Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc. 
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

Input is a sequence of lines, each containing two positive integers s and d.

Output

For each line of input, output one line containing either a single integer giving the amount of surplus for the entire year, or output Deficit if it is impossible.

Sample Input

59 237
375 743
200000 849694
2500000 8000000

Sample Output

116
28
300612
Deficit
这里翻译一下题目,原先没看懂题:
题目大意:有家公司每个月有盈余s 和亏损d但不知道具体是那个月 只知道一年中每个连续的五个月都是亏损的。要求求出该公司这一年里最大的盈利的可能金额 若不能盈利就输出Deficit
注意如果s>4d也是要输出Deficit的   
我是利用贪心做的,依次检查1-5月,2-6月,。。。。先检查1-5月,将s放在前面,看看最多可以有几个月盈利,在检查2-6月,因为2-5月已经知道,所以看6月如果是s符合条件,那么6月是s,否则是d,依次找出所有月的盈利是s还是亏损d,算出是盈利还是亏损即可。
查网上还有一中简单方法,直接穷举,5个月统计一次,可能出现亏损的情况如下:

1. SSSSD -> SSSSDSSSSDSS

2. SSSDD -> SSSDDSSSDDSS

3. SSDDD -> SSDDDSSDDDSS

4. SDDDD -> SDDDDSDDDDSD

只有这几种情况,依次试一下即可

下面是我写的AC

 #include <iostream>
using namespace std; int main() {
int s,d;
int res[];
int sum[];
while(cin>>s>>d){
int tmp=;
for(int i=;i<;i++){
if(i*s-(-i)*d<=&&(i+)*s-(-i-)*d>){
tmp=i;
break;
}
}
//cout<<tmp<<endl;
if(tmp==){
cout<<"Deficit"<<endl;
continue;
}
for(int i=;i<tmp;i++){
res[i]=s;
}
for(int i=tmp;i<;i++){
res[i]=-d;
}
sum[]=res[];
//cout<<sum[0]<<endl;
for(int i=;i<;i++){
sum[i]=sum[i-]+res[i];
// cout<<sum[i]<<endl;
}
for(int i=;i<;i++){
int tsum=;
tsum=sum[i-]-sum[i-];
if(tsum+s<=){
sum[i]=sum[i-]+s;
}else{
sum[i]=sum[i-]-d;
}
//cout<<sum[i]<<endl;
}
if(sum[]<=){
cout<<"Deficit"<<endl;
}else{
cout<<sum[]<<endl;
}
}
return ;
}

Y2K Accounting Bug - 2586的更多相关文章

  1. ** poj Y2K Accounting Bug 2586

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10117   Accepted: 50 ...

  2. 贪心 POJ 2586 Y2K Accounting Bug

    题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...

  3. Poj 2586 / OpenJudge 2586 Y2K Accounting Bug

    1.Link: http://poj.org/problem?id=2586 2.Content: Y2K Accounting Bug Time Limit: 1000MS   Memory Lim ...

  4. poj 2586 Y2K Accounting Bug

    http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...

  5. poj 2586 Y2K Accounting Bug (贪心)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8678   Accepted: 428 ...

  6. POJ 2586:Y2K Accounting Bug(贪心)

    Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10024 Accepted: 4990 D ...

  7. POJ 2586 Y2K Accounting Bug(枚举洪水问题)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

  8. POJ 2586 Y2K Accounting Bug 贪心 难度:2

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10537   Accepted: 52 ...

  9. POJ 2586 Y2K Accounting Bug(枚举大水题)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

随机推荐

  1. POJ 2566:Bound Found(Two pointers)

    [题目链接] http://poj.org/problem?id=2566 [题目大意] 给出一个序列,求一个子段和,使得其绝对值最接近给出值, 输出这个区间的左右端点和区间和. [题解] 因为原序列 ...

  2. [Git]Git 常用的操作命令

    创建本地仓库 git init 获取远程仓库 git clone [url] 例如:git clone https://github.com/you/yourpro.git 创建远程仓库 添加一个新的 ...

  3. SQLServer To MySQL 解决方案

        最近在忙一个项目,就不详写了.过两天不忙了把项目总结一下.   思路: Access作为桥梁   1.SQLServer To Access 2007 在access里直接导入 2.Use t ...

  4. Overview of iOS Crash Reporting Tools: Part 1/2

    Believe it or not, developers are not perfect, and every once in a while you might have a (gasp!) bu ...

  5. XCode下的iOS单元测试

    XCode 内置了 OCUnit 单元测试框架,但目前最好用的测试框架应该是 GHUnit.通过 GHUnit + OCMock 组合,我们可以在 iOS 下进行较强大的单元测试功能.本文将演示如何在 ...

  6. 为什么实现Serializbale接口就能够进行序列化?

    从所周知,Serializbale接口是个空的接口,并没有定义任何方法.那么问题来了,为什么需要序列化的接口只要实现Serializbale接口就能够进行序列化? 这要从序列化过程的源码说起.举个例子 ...

  7. 转:MyBatis学习总结(Mybatis总结精华文章)

    http://www.cnblogs.com/xdp-gacl/tag/MyBatis%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/ 当前标签: MyBatis学习总结   ...

  8. mysql 存储过程 演示样例代码

    drop procedure if exists P_SEQUENCE; /** 暂省略包 @AUTO LIANGRUI 2014/6/27 T_PRO_PRODUCT 表 排序 对整个表进行按序号排 ...

  9. php正则表达式基本

    一.正则表达式的组成 1.分隔符,可以是除了字母,数字,反斜线及空白以外的任何字符,比如/,!,#,%,|,~等;通常有/,!,~ 2.表达式:由一些特殊字符和非特殊字符组成. 3.修饰符:用于开启或 ...

  10. 使用RTTI为继承体系编写”==”运算符

    转载请注明出处:http://www.cnblogs.com/inevermore/p/4012079.html   RTTI,指的是运行时类型识别技术.   先看一个貌似无关的问题:   为继承体系 ...