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. SpringApplication到底run了什么(下)

    在上篇文章中SpringApplication到底run了什么(上)中,我们分析了下面这个run方法的前半部分,本篇文章继续开工 public ConfigurableApplicationConte ...

  2. QGraphicsItem鼠标精准拾取(pick/select)研究

    在QT场景视图中,一个2D图形项是一个QGraphicsItem,我们可以通过继承来定义我们自己的图形项. 主要有以下三个虚函数需要重点关注: 1)   边界矩形(必须实现) virtual QRec ...

  3. i春秋——“百度杯”CTF比赛 十月场——Not Found(http请求方法,client-ip伪造ip)

    这道题也是让我很迷... 打开就是not found,让我一度以为是服务器挂了,细看发现有个404.php 访问也没发现什么东西,只有来自出题人的嘲讽 haha~ 不过在首页的header中发现个奇怪 ...

  4. Android Xutils3 完全解析

    1.先来认识一下xUtils3 1)xUtils3简介 xUtils是基于Afinal开发的目前功能比较完善的一个Android开源框架,最近又发布了xUtil3.0,在增加新功能的同时又提高了框架的 ...

  5. 个人项目-WC (java实现)

    一.Github地址:https://github.com/734635746/WC 二.PSP表格 PSP2.1 Personal Software Process Stages 预估耗时(分钟) ...

  6. Linux小知识点

    磁盘 Linux的磁盘类型有IDE和SCSI两种. IDE的命名方式是采用/dev/hdx(x代表磁盘块),其下的分区则是/dev/hdxy(y代表该磁盘上的分区号) SCSI则是采用/dev/sdx ...

  7. 用js怎么来判断我已点击了窗体中“关闭”按钮?

    onbeforeunload 事件在即将离开当前页面(刷新或关闭)时触发. 该事件可用于弹出对话框,提示用户是继续浏览页面还是离开当前页面. 对话框默认的提示信息根据不同的浏览器有所不同,标准的信息类 ...

  8. 杨巧丽 实验十四 团队项目评审&课程学习总结

    实验十四 团队项目评审&课程学习总结 项目 内容 这个作业属于哪个课程 (https://www.cnblogs.com/nwnu-daizh/) 这个作业的要求在哪里 (https://ww ...

  9. PHP将图片转base64格式函数

    base64的好处是什么?今天在跟小伙伴讨论这个问题,要是全站用Php把图片转为base64行不行? 1. 提升性能: 网页上的每一个图片,都是需要消耗一个 http 请求下载而来的, 图片的下载始终 ...

  10. vue+ typescript 使用parcel 构建

    parcel 是一个零配置的前端构建工具,相比webpack 更快,同时使用简单以下是 一个简单的使用typescript 开发vue 应用,同时使用parcel 构建,同时集成了docker 构建, ...