Y2K Accounting Bug
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12251   Accepted: 6202

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

  1. 59 237
  2. 375 743
  3. 200000 849694
  4. 2500000 8000000

Sample Output

  1. 116
  2. 28
  3. 300612
  4. Deficit
  5. 题意:12个月每个月要么盈利s,要么亏损d,连续五个月都是亏损的,即1-52-6,3-7,4-8,5-9,6-10,7-11,8-12;求一年最大盈利
    分析:想了半天确实没想出怎么解,看了题解,却又感觉那么的合情合理,贪心考虑边界http://blog.csdn.net/lyy289065406/article/details/6642603
在保证连续5个月都亏损的前提下,使得每5个月中亏损的月数最少。
              x=1:  ssssd,ssssd,ss    d>4s     赢利10个月  10s-2d
              x=2:  sssdd,sssdd,ss    2d>3s    赢利8个月     8s-4d
              x=3:  ssddd,ssddd,ss    3d>2s    赢利6个月     6s-6d 
              x=4:  sdddd,sdddd,sd    4d>s     赢利3个月     3s-9d
              x=5:  ddddd,ddddd,dd    4d<s     无赢利
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. using namespace std;
  6. long long s,d;
  7. char str[] = "Deficit";
  8.  
  9. int main()
  10. {
  11. while(scanf("%I64d%I64d", &s, &d) != EOF)
  12. {
  13. if(d > * s)
  14. {
  15. if( * s - * d > )
  16. {
  17. printf("%I64d\n", * s - * d);
  18. }
  19. else
  20. {
  21. printf("%s\n", str);
  22. }
  23. }
  24. else if( * s < * d )
  25. {
  26. if( * s - * d > )
  27. {
  28. printf("%I64d\n", * s - * d);
  29. }
  30. else
  31. {
  32. printf("%s\n", str);
  33. }
  34. }
  35. else if( * s < * d)
  36. {
  37. if( * s - * d > )
  38. {
  39. printf("%I64d\n", * s - * d);
  40. }
  41. else
  42. {
  43. printf("%s\n", str);
  44. }
  45. }
  46. else if(s < * d)
  47. {
  48. if( * s - * d > )
  49. {
  50. printf("%I64d\n", * s - * d);
  51. }
  52. else
  53. {
  54. printf("%s\n", str);
  55. }
  56. }
  57. else
  58. {
  59. printf("%s\n", str);
  60. }
  61. }
  62.  
  63. return ;
  64. }

POJ2586Y2K Accounting Bug(贪心 + 不好想)的更多相关文章

  1. poj 2586 Y2K Accounting Bug (贪心)

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

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

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

  3. Y2K Accounting Bug(贪心)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10945   Accepted: 54 ...

  4. POJ2586Y2K Accounting Bug

    http://poj.org/problem?id=2586 Description Accounting for Computer Machinists (ACM) has sufferred fr ...

  5. POJ2586 Y2K Accounting Bug(贪心)

    题目链接. 题目大意: 题目相当晦涩难懂啊. 一年的12个月,每5个月统计一次,如从1~5,2~6,3~7,...,8~12共统计了8次,已知每次都deficit,问这一年有没有盈利的可能. 一个月s ...

  6. POJ-2586 Y2K Accounting Bug贪心,区间盈利

    题目链接: https://vjudge.net/problem/POJ-2586 题目大意: MS公司(我猜是微软)遇到了千年虫的问题,导致数据大量数据丢失.比如财务报表.现在知道这个奇特的公司每个 ...

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

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

  8. 贪心 POJ 2586 Y2K Accounting Bug

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

  9. poj2586 Y2K Accounting Bug(贪心)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=2586 ------ ...

随机推荐

  1. js轮询

    业务场景为5秒ajax方式请求服务端更新状态,setInterval带参数模式. var objTimer = null; //创建 objTimer=setInterval(function(){l ...

  2. 浏览器默认样式(User Agent Stylesheet)

    原文:http://www.zjgsq.com/898.html 不同浏览器对于相同元素的默认样式并不一致,这也是为什么我们在CSS的最开始要写 * {padding:0;marging:0}: 不过 ...

  3. MVC权限验证之ActionFilterAttribute

    参考:http://www.cnblogs.com/waitingfor/archive/2011/12/27/2303784.html ActionFilterAttribute是Action过滤类 ...

  4. php基础23:数值与数值函数

    <?php //1.自动转换 $a = 5; $b = "5a"; $c = $a + $b; echo $c; echo "<br>"; $ ...

  5. C#模拟POST提交表单(一)--WebClient

    C#的提交表单方式主要有两种WebClient与HttpWebRequest,这里先介绍一种 WebClient,转送门:http://msdn.microsoft.com/zh-cn/library ...

  6. vbs实现的支持拖动的txt文本切割器

    vbs实现的支持拖动的txt文本切割器 作者: 字体:[增加 减小] 类型:转载 时间:2008-06-20我要评论 用vbs实现的txt文本文件切割器,默认为8000个字符切为一个文件.支持拖动. ...

  7. 足球运动训练心得及经验分析-c语言学习调查

    在准备预备作业02之前,我参考娄老师的提示,阅读了<[做中学(Learning By Doing)]之乒乓球刻意训练一年总结>一文. 在文章描述的字里行间,给予我的印象是系统.负责,娄老师 ...

  8. Expectation maximization - EM算法学习总结

    原创博客,转载请注明出处 Leavingseason http://www.cnblogs.com/sylvanas2012/p/5053798.html EM框架是一种求解最大似然概率估计的方法.往 ...

  9. sass,compass让开发效率飞起

    最近开始学习并且使用,发现使用它写起css来真的是各种爽 安装sass,compass sass是依赖于ruby的,必须先安装Ruby,点击下载 下载完ruby之后,使用命令行安装sass       ...

  10. 我最优惠网系列(1)——HTML 解析类库HtmlAgilityPack

    0. 序言 在开发我最优惠网的过程中,遇到一些问题和技术点,写出来和大家分享,也是我自己对近期工作的整理和记录,预计会有解析HTML类库.本地缓存.链接跳转和C#中执行js代码技巧等方面. 1. Ht ...