Y2K Accounting Bug
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9691   Accepted: 4838

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

【题目来源】

Waterloo local 2000.01.29

【题目大意】

有一家公司,每5个月的营销额总是亏损的,现在给你两个数字,分别表示这个公司每个月可能的盈利额或亏损额,现在要你求这个公司满足每5个月总是亏损的

条件,一年下来这个公司可能盈利的最大值,若为负,则输出"Deficit".

【题目分析】

一个简单的贪心,只要我们在判断的时候首先考虑盈利额最大的,按照盈利额减少的情况来判断,这就满足了贪心的求解方法。

#include<cstdio>
int main()
{
int s,d,t;
while(~scanf("%d%d",&s,&d))
{
if(*s-d<) t=*s-*d;
else if(*s-*d<) t=*s-*d;
else if(*s-*d<) t=*s-*d;
else if(s-*d<) t=*s-*d;
else t=-;
if(t<)
printf("Deficit\n");
else printf("%d\n",t);
}
return ;
}

贪心 --- Y2K Accounting Bug的更多相关文章

  1. 贪心 POJ 2586 Y2K Accounting Bug

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

  2. poj2586 Y2K Accounting Bug(贪心)

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

  3. poj 2586 Y2K Accounting Bug (贪心)

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

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

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

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

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

  6. Y2K Accounting Bug(贪心)

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

  7. [POJ2586]Y2K Accounting Bug

    [POJ2586]Y2K Accounting Bug 试题描述 Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...

  8. POJ2586——Y2K Accounting Bug

    Y2K Accounting Bug   Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...

  9. poj 2586 Y2K Accounting Bug

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

随机推荐

  1. 同一个POD中默认共享哪些名称空间

    如果通过POD的形式来启动多个容器那么它们的名称空间会是共享的么,所以我这里讨论是在默认情况下同一个POD的不同容器的哪些名称空间是打通的.这里先说一下结论,共享的是UTS.IPC.NET.USER. ...

  2. HandBrake-QuickSync-Mac (内容:QuickSync encoder via VideoToolbox )

    来源:https://github.com/galad87/HandBrake-QuickSync-Mac/commit/2c1332958f7095c640cbcbcb45ffc955739d594 ...

  3. JavaWeb 使用Filter实现自动登录

    思路 使用cookie存储账号.密码,使用Filter拦截,从cookie中取出账号.密码.若用户要注销|登出.不再想使用自动登录,将cookie的有效期设置为0即可. 浏览器可以查看Cookie,不 ...

  4. (原)在anaconda3+ubuntu16.04中编译Pose flow中的deepmatching动态库

    转载请注明出处: https://www.cnblogs.com/darkknightzh/p/11285239.html 参考网址: https://github.com/YuliangXiu/Po ...

  5. shell $x的含义

    linux中shell变量$#,$@,$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行 ...

  6. 一文搞定PGA_LGA_BGA

    概述 什么是LGA.PGA.BGA类型的封装?众所周知,CPU封装的类型主要为三种:LGA,PGA,BGA,其中LGA封装是最常见的,intel处理器都是采用这种类型的封装,而PGA封装则是AMD常用 ...

  7. kernel: nfsd: too many open TCP sockets, consider increasing the number of threads

    在/var/log/syslog中看到如下报错:   kernel: nfsd: too many open TCP sockets, consider increasing the number o ...

  8. db.sqlite如何导出转储为sql文件

    在使用 django框架写博客时,用的是sqlite数据库,想要将其中的db.sqlite转储为sql文件, 我是在linux下使用的,很多linux系统下都自带sqlite 检查是否安装sqlite ...

  9. 第07节-开源蓝牙协议BTStack框架代码阅读(上)

    首先来看一下,对于硬件操作,它是如何来进行处理的.在上篇文章中曾说过,在main函数里面它会调用硬件相关的代码,调用操作系统相关的代码.在BTStack中,可以搜索一下main.c,将会发现有很多ma ...

  10. 葫芦娃团队对火鸡堂、基于云的胜利冲锋队团队的Beta产品测试报告

    Beta项目互测 课程名称:软件工程1916|W(福州大学) 作业要求:Beta阶段团队项目互评 团队名称:葫芦娃队 作业目标:Beta项目互测 一.火鸡堂团队产品测试 1.截图(推荐用动态gif图录 ...