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. com和dll(一)

    1.com为一种规范,使不同语言能在二进制层面上进行交互. 2.dll为ms的一种程序打包文件,使程序的代码能分开打包编译,并能在运行时共享.

  2. struts 文件上传下载

    上传 1.编写上传action类 UploadAction.java package jxf.b_upload; import java.io.File; import java.io.IOExcep ...

  3. UVA 11300 Spreading the Wealth (数学推导 中位数)

    Spreading the Wealth Problem A Communist regime is trying to redistribute wealth in a village. They ...

  4. UIView-图层方法

    // // ViewController.m // UIView-图层概念 // // Created by wangtouwang on 15/5/5. // Copyright (c) 2015年 ...

  5. Headfirst设计模式的C++实现——简单工厂模式(Simple Factory)之二

    为了引出后续的工厂方法,把在简单工厂模式的基础上增加了新功能——加盟店 简而言之就是把原来的单一简单工厂(能生产cheese和greek两种pizza)细分成了纽约地区的和芝加哥地区的(每种地区都能生 ...

  6. Java进程CPU使用率高排查

    Java进程CPU使用率高排查 生产java应用,CPU使用率一直很高,经常达到100%,通过以下步骤完美解决,分享一下.1.jps 获取Java进程的PID.2.jstack pid >> ...

  7. WinForm聊天室

    前几天开始学Socket编程,跟着老师一点一点的做.最后做了一个WinForm版的小聊天室.这个聊天室的客户端和服务端都只是在本机上运行. 这里我首先和大家谈谈我对聊天室的一点理解,聊天室其实是服务端 ...

  8. html5有什么布局标签

    header h1 nav ul li a section(id) div h3 article figure img article h4 header time datetime='' body ...

  9. Redis的PHP操作手册(自用)

    String 类型操作 string是redis最基本的类型,而且string类型是二进制安全的.意思是redis的string可以包含任何数据.比如jpg图片或者序列化的对象 $redis-> ...

  10. javaScript & jquery完美判断图片是否加载完毕

    好久没写东西了,正好最近因为工作需要,写了一个瀑布流异步加载的程序. 今天就不谈瀑布流,来谈一下关于load的问题. ----------------------------------------- ...