转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents

题目链接:http://poj.org/problem?id=2586

----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋:http://user.qzone.qq.com/593830943/main
----------------------------------------------------------------------------------------------------------------------------------------------------------
Language: Default
Y2K Accounting Bug
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9979   Accepted: 4970

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

题意比較难懂,事实上仅仅要读懂题意,就非常easy了。
大意是一个公司在12个月中,或固定盈余s,或固定亏损d.
但记不得哪些月盈余,哪些月亏损,仅仅能记得连续5个月的代数和总是亏损(<0为亏损),而一年中仅仅有8个连续的5个月,分别为1~5,2~6,…,8~12
问全年是否可能盈利?若可能,输出可能最大盈利金额,否则输出“Deficit".

思路:贪心思想,每连续5个月中,在保证这5个月经营之和为亏损的情况下,亏损的月数肯定应尽量往后选,盈利的月数应尽量往前选。

一共五种情况:

把5种情况能够归纳为关于s的判定条件:

0 <= s <1/4d           每连续5个月种至少1个月D

1/4d <= s < 2/3d          每连续5个月种至少2个月D

2/3d <= s < 3/2d          每连续5个月种至少3个月D

3/2d <= s < 4d           每连续5个月种至少4个月D

4d <= s                全年各月必亏损

代码例如以下:

#include <iostream>
using namespace std;
int main()
{int s, d, flag;while(cin>>s>>d){int sum = 0;flag = 0;if(0<=s && s<(1.0/4)*d){sum = 10*s - 2*d;}else if((1.0/4)*d<=s && s<(2.0/3)*d){sum = 8*s-4*d;}else if((2.0/3)*d<=s && s<(3.0/2)*d){sum = 6*s-6*d;}else if((3.0/2)*d<=s && s<4*d){sum = 3*s-9*d;}else if(4*d <= s){flag = 1;}if( sum < 0)flag = 1;if(flag)cout<<"Deficit"<<endl;elsecout<<sum<<endl;}return 0;
}

poj2586 Y2K Accounting Bug(贪心)相关推荐

  1. poj2586 Y2K Accounting Bug

    2017-10-6 解答 我用的枚举法,应该用的贪心 代码 #include<iostream> using namespace std;const int N = 12; long lo ...

  2. Y2K Accounting Bug poj-2586

    题目链接:2586 -- Y2K Accounting Bug 题面: 题意: 给定s是盈余,d是亏损,每5个月给定这5个月的亏损,如果一个月的总成绩大于等于0就输出值,否则就 Deficit 思路: ...

  3. POJ 2586 Y2K Accounting Bug(贪心)

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

  4. Y2K Accounting Bug(poj2586)

    题意: 有一个公司由于某个病毒使公司赢亏数据丢失,但该公司每月的 赢亏是一个定数,要么一个月赢利s,要么一月亏d.现在ACM只知道该公司每五个月有一个赢亏报表,而且每次报表赢利情况都为亏.在一年中这样 ...

  5. python运维脚本面试_运维开发工程师 面试题 shell编程

    1. 32位随机密码生成 cat /proc/sys/kernel/random/uuid | tr -d '-' 2.查看当前系统每个ip的tcp连接数 -n 强制显示IP地址 -t 显示TCP连接 ...

  6. CUGBACM22级暑假小学期训练-贪心

    CUGBACM22级暑假小学期训练-贪心 A - 种树 题意:给一个环,取m个节点,不能取相邻节点,令所取节点的权值之和最大化 思路:dp,用到了最大流中建立反向边的思想使得这个贪心能够"反 ...

  7. NKU 专题一 题解

    A - Flip Game 总的情况数只有2^16次方种,显然直接bfs就可以了 1 #include<iostream> 2 #include<queue> 3 #inclu ...

  8. HOJ题目分类//放这儿没事刷刷学算法!嘻嘻!

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  9. π-Algorithmist分类题目(3)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(3) Probability ...

最新文章

  1. php的yii2框架下开发环境xampp,vim,xdebug,DBGp的搭建
  2. 自然语言处理的现实应用
  3. 十进制数转为十六进制字符串
  4. SAP CRM呼叫中心里多重Contact person confirm的处理
  5. 即时大数据流处理=即时风暴
  6. XCoreRedux框架:Android UI组件化与Redux实践
  7. 利用Underscore求数组的交集、并集和差集
  8. 【原创】uC/OS 中LES BX,DWORD PTR DS:_OSTCBCur的作用及原理
  9. mysql+e+文件+xls_TP5+PHPexcel导入xls,xlsx文件读取数据
  10. 如何用jQuery获得select的值
  11. 从19本书中选取五本,并且要求这五本互相不相邻,一共有多少种方法?
  12. 高等数学_第一章第一节_映射与级数
  13. python其他字符转换为ascii码
  14. DirectX 9 游戏汉化详解
  15. Java LDAP统一身份认证
  16. three.js 05-08 之 TorusKnotGeometry 几何体
  17. Go适合做什么?为何这么多人偏爱Go语言?
  18. 深圳学校积分计算机,深圳积分入户初级计算机证书,居然也能积这么多分!
  19. python穷举法列举_穷举法
  20. 机器人阿郎_机械人阿郎

热门文章

  1. Exadata Griddisk Can't be auto added
  2. 《构建高可用VMware vSphere 5.X虚拟化架构》——第2章 构建高可用vCenter Server 2.1vCenter Server版本以及运行环境的选择...
  3. 通过修改PHP源代码解决Nginx下WebShell跨站的问题
  4. WCF BasicHttpBinding 安全解析(1)BasicHttpBinding基本配置
  5. 在Ubuntu18.04上安装Nvidia驱动
  6. 洛谷 P3745 [六省联考2017]期末考试
  7. c#.net利用RNGCryptoServiceProvider产生任意范围强随机数的办法
  8. Storm介绍及核心组件和编程模型
  9. Swift去除两边的特定字符(空格或其它)
  10. cacti yum快速部署