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. IntelliJ IDEA14 和 Maven 系列:使用IntelliJ IDEA 14和Maven 7 创建java web项目(一)

    Intellij IDEA作为最好的Java IDE,创建Maven项目还是比较简单的,但是创建一个Maven Web项目还是要修改一些配置的,下面进行总结整理. 1前言 在创建项目中,IDEA提供了 ...

  2. eclipse+PyDev 中报错"scrapy.spiders.Spider" ,可用"# @UndefinedVariable"压制.

    # -*- coding:utf-8 -*- ''' Created on 2015年10月22日 (1.1) 例子来源: http://scrapy-chs.readthedocs.org/zh_C ...

  3. DAG模型——硬币问题

    硬币问题 有n种硬币,面值分别为V1,V2,...,Vn,每种都有无限多.给定非负整数S,可以选用多少个硬币,使得面值之和恰好为S?输出硬币数目的最小值和最大值.1<=n<=100, 0& ...

  4. java编程思想,对象导论

    程序设计的本质就是使用编程语言解决某一类具体问题.对问题的定义叫建模,例如定义问题域中的各种名词,动作,结果等.针对具体的问题提出的解决方案叫算法. 面向对象程序设计的挑战之一,就是在问题空间的元素和 ...

  5. mod_wsgi

    配置: WSGIScriptAlias /var/www/wsgi-scripts/simple.wsgi def application(environ, start_response): outp ...

  6. 安装交叉编译arm-linux-gcc环境

    设置好交叉编译的执行文件路径贴加到环境变量PATH 设置如下 export PATH=$PATH:/XXX/XXX/bin /etc/profile /~/.bashrc source  /etc/p ...

  7. Quartz 之 windowService

    (一)创建服务 QuarzService using System.ServiceProcess;using System.Text; using Quartz;using Quartz.Impl; ...

  8. CentOS 6.4 使用第三方源

      1.EPEL源 CentOS 6.x 32-bit (x86/i386):rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/ep ...

  9. JBPM4中常用概念总结

    1. 流程定义(Process Definition)    流程定义是记录在xml文件中的对流程的描述,它包含唯一的流程开始节点和多个流程功能节点,每个节点之间使用transition进行连接. P ...

  10. LDR伪指令与ADR伪指令的区别

    测试代码 ldr r0, _start adr r0, _start ldr r0, =_start nop mov pc, lr _start: nop 设置代码的起始地址为 0x0c008000, ...