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. kkpager 实现ajax分页查询

    前台分页数据,适合数据少量的时候,因为分页的数据是从后台获取的,大数据的话不建议使用 现看前台代码: @{ Layout = null; } <!DOCTYPE html> <htm ...

  2. JAVA I/O系统 Thinking in Java 之 File类

    File类的文件具有一定的误导性,我们可能会认为它指代的是文件,实际上并非如此.它技能代表一个特定文件的名称,又能代表一个目录下的一组文件的名称.如果它指的是一个文件集,我们就可以对此集合调用list ...

  3. maven 学习---Maven启用代理访问

    如果你的公司正在建立一个防火墙,并使用HTTP代理服务器来阻止用户直接连接到互联网.如果您使用代理,Maven将无法下载任何依赖. 为了使它工作,你必须声明在 Maven 的配置文件中设置代理服务器: ...

  4. CentOS7 firewalld防火墙规则

    在CentOS7里有几种防火墙共存:firewalld.iptables.ebtables,默认是使用firewalld来管理netfilter子系统,不过底层调用的命令仍然是iptables等. f ...

  5. JMETER 使用断言

    断言概念 断言就是在执行某个请求后,根据返回的结果,判断返回是否正确,如果不正确,则表示事务失败. 添加断言 启动流程时返回的数据是一个 json对象,结构为 {success:true,msg:&q ...

  6. ROS学习笔记(二) :使用roslaunch

    目录 roslaunch roslaunch的使用 以turtlesim为例 roslaunch roslaunch是ros自带的一个库,使用roslaunch可以同时运行多个节点,通过编写launc ...

  7. MySQL服务的构成(二)

    一.什么是实例 这里的实例不是类产生的实例对象,而是Linux系统下的一种机制 1.MySQL的后台进程+线程+预分配的内存结构. 2.MySQL在启动的过程中会启动后台守护进程,并生成工作线程,预分 ...

  8. 转:宏定义的极致发挥---让你的普通C++类轻松支持IDispatch自动化接口(二)

    Posted on 2011-01-13 20:44 一桶浆糊 这是上一篇博客<宏定义的极致发挥---让你的普通C++类轻松支持IDispatch自动化接口>所展示的示例代码的改进版,改进 ...

  9. nginx 缓存服务

    1.nginx 缓存 upstream imooc { server 116.62.103.228:8001; server 116.62.103.228:8002; server 116.62.10 ...

  10. HTML基础一-html、CSS

    一.HTML标签 前端语言 HTML-将页面展现出来    CSS-修饰前端标签 让HTML更好看 css 对html 进行修饰    JS-能够让页面动起来 HTML htyper text mar ...