http://poj.org/problem?id=2586

大意是一个公司在12个月中,或固定盈余s,或固定亏损d.

但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为亏损),而一年中只有8个连续的5个月,分别为1~5,2~6,…,8~12

问全年是否可能盈利?若可能,输出可能最大盈利金额,否则输出“Deficit".

贪心,符合最优子结构性质。5个月统计一次都亏空,那么有5种情况:
      1、若SSSSD亏空,那么全年可能最大盈利情况为: SSSSDSSSSDSS
      2、若SSSDD亏空,那么全年可能最大盈利情况为:SSSDDSSSDDSS
      3、若SSDDD亏空,那么全年可能最大盈利情况为: SSDDDSSDDDSS
      4、若SDDDD亏空,那么全年可能最大盈利情况为: SDDDDSDDDDSD
      5、若DDDDD亏空,那么全年可能最大盈利情况为: DDDDDDDDDDDD
                                                       Y2K Accounting Bug
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10761   Accepted: 5391

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
 #include<iostream>
#include<cstring>
#include<cstdio>
int main()
{
int s,d;
while(~scanf("%d%d",&s,&d))
{
int flag=;
int ans=;
if(*s-d<)
{
ans=*s-*d;
if(ans<=)
flag=;
}
else if(*s-*d<)
{
ans=*s-*d;
if(ans<=)
flag=;
}
else if(*s-*d<)
{
ans=*s-*d;
if(ans<=)
flag=; }
else if(s-*d<)
{
ans=*s-*d;
if(ans<=)
flag=; }
else
{
printf("Deficit\n");
continue;
}
if(flag)
printf("Deficit\n");
else
printf("%d\n",ans); }
return ;
}

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

  1. 贪心 POJ 2586 Y2K Accounting Bug

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

  2. poj 2586 Y2K Accounting Bug (贪心)

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

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

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

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

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

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

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

  6. POJ - 2586 Y2K Accounting Bug (找规律)

    Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...

  7. [POJ 2586] Y2K Accounting Bug (贪心)

    题目链接:http://poj.org/problem?id=2586 题目大意:(真难读懂啊)给你两个数,s,d,意思是MS公司每个月可能赚钱,也可能赔钱,如果赚钱的话,就是赚s元,如果赔钱的话,就 ...

  8. 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) ...

  9. poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)

    #include <iostream> using namespace std; /*248K 32MS*/ int main() { int s,d; while(cin>> ...

随机推荐

  1. Fxcop 初体验

    代码质量对于软件项目的成败很重要,这点我想大家都明白.那么在一个软件团队中如何保证代码质量呢?对于这个问题不同的人可能会有不同的答案,对于我而言我觉得做好两点代码质量基本就可以保证了: 1.代码规范( ...

  2. SSH中调用另一action的方法(chain,redirect)

      从一个Action直接跳到另一个Action中,Struts提供了两种结果类型可以实现:chain.redirect.        从Servlet中学到重定向是不能保留参数的,也就是说重定向了 ...

  3. ISO 学习笔记 2015-03-15

    Objective--C 一 关键字 @property 定义变量函数 @synthesize 实现变量函数 二 函数 alloc 分配内存 init 初始化 new 替代上面两个函数 分配内存,并且 ...

  4. 转(sphinx 多索引使用 方法 )

    1 http://blog.csdn.net/adparking/article/details/7080278  文章不错 总结 1.索引合并问题,前面已经解释过,两个索引合并时,都要读入,然后还要 ...

  5. demo_06Canvas

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. wampserver下升级php7

    1.下载php7   http://windows.php.net/download#php-7.0 选择 VC14 x86 Thread Safe  64位选X64 32位选X86 2.下载VC14 ...

  7. 【python之旅】python的基础三

    目录: 1.装饰器 2.迭代器&生成器 3.Json & pickle 数据序列化 4.软件目录结构规范  一.装饰器 定义:本质是函数,(装饰其他函数)就是为其他函数添加附加功能 原 ...

  8. CPU/寄存器/内存

    因为要了解多线程,自然少不了一些硬件知识的科普,我没有系统学习过硬件知识,仅仅是从书上以及网络上看来的,如果有错误请指出来. CPU,全名Central Processing Unit(中央处理器). ...

  9. HDU 1394 Minimum Inversion Number 线段树

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=1394 没看到多组输入,WA了一万次...... 其实很简单,有人暴力过得,我感觉归并排序.二叉排序树求逆 ...

  10. to disable the entity lazy load, The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

    The ObjectContext instance has been disposed and can no longer be used for operations that require a ...