Y2K Accounting Bug
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 15626   Accepted: 7843

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

  1. 59 237
  2. 375 743
  3. 200000 849694
  4. 2500000 8000000

Sample Output

  1. 116
  2. 28
  3. 300612
  4. Deficit

Source

题意:一个公司每一个月的情况为:盈利s或亏损d。 每五个月进行一次统计,共统计八次(1-5月一次,2-6月一次.......) 统计的结果是这八次都是亏空。

问题:判断全年是否能盈利,如果能则求出最大的盈利。 如果不能盈利则输出Deficit

思路:按d从大到小枚举情况,最开始每五个月里最多4个s

eg:若d>4s,则对于答案的排列里每五个月最多只有4个s,这样存在最多s的排列为:ssssdssdssss 10s+2d

  若2d>3s,则最多3个s 排列:sssddssddsss 8s+4d...

  ...

代码:

  1. #include "cstdio"
  2. #include "stdlib.h"
  3. #include "iostream"
  4. #include "algorithm"
  5. #include "string"
  6. #include "cstring"
  7. #include "queue"
  8. #include "cmath"
  9. #include "vector"
  10. #include "map"
  11. #include "set"
  12. #define db double
  13. #define inf 0x3f3f3f
  14. #define mj
  15. typedef long long ll;
  16. using namespace std;
  17. const int N=1e5+;
  18. int profit(int s, int d)
  19. {
  20. if (d > * s)
  21. return -*d+*s;
  22. else if ( * d > * s)
  23. return -*d+*s;
  24. else if ( * d > * s)
  25. return -*d+*s;
  26. else if ( * d > s)
  27. return -*d+*s;
  28. else
  29. return -;
  30. }
  31.  
  32. int main() {
  33. int s, d;
  34. while (cin >> s >> d)
  35. {
  36. int sum = profit(s, d);
  37. if (sum >= )
  38. {
  39. cout << sum << endl;
  40. }
  41. else {
  42. cout << "Deficit" << endl;
  43. }
  44. }
  45. return ;
  46. }

POJ 2586 贪心+枚举的更多相关文章

  1. 贪心 POJ 2586 Y2K Accounting Bug

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

  2. POJ 1018 Communication System 贪心+枚举

    看题传送门:http://poj.org/problem?id=1018 题目大意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m个厂家提供生产,而每个厂家生产的同种设备都 ...

  3. poj 1873 凸包+枚举

    The Fortified Forest Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6198   Accepted: 1 ...

  4. [POJ 2586] Y2K Accounting Bug (贪心)

    题目链接:http://poj.org/problem?id=2586 题目大意:(真难读懂啊)给你两个数,s,d,意思是MS公司每个月可能赚钱,也可能赔钱,如果赚钱的话,就是赚s元,如果赔钱的话,就 ...

  5. poj 2586 Y2K Accounting Bug (贪心)

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

  6. 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) ...

  7. poj 2010 Moo University - Financial Aid(优先队列(最小堆)+ 贪心 + 枚举)

    Description Bessie noted that although humans have many universities they can attend, cows have none ...

  8. poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)

    #include <iostream> using namespace std; /*248K 32MS*/ int main() { int s,d; while(cin>> ...

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

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

随机推荐

  1. 在sublime text3下,用快捷键把文件打开到浏览器中

    使用背景 在编辑html或者js文件的时候,是否想在浏览器中预览一下, 你的步骤可能是这样的: 找到编辑文件的位置, 右键使用某一浏览器打开.如果是这样,你就out了, 因为在sublime中有更加简 ...

  2. [Coding Style] CSS coding style

    CSS coding style Note 结合实际工作中的规范和推荐大家使用的CSS书写规范.顺序这篇文章整合而成 Navigation CSS 书写顺序 CSS 常用文件命名 CSS 常用命名规范 ...

  3. Javascript Number

    Number 对象 Number对象是原始值的包装对象 创建Number对象的语法: var myNum = new Number(value): var myNum = Number(value): ...

  4. ngnix反向代理

    https://blog.csdn.net/sherry_chan/article/details/79055211

  5. ArcGIS中Features与JSON的互相转化

    实际操作过程非常简单,这里就简单记录下转换工具的位置:

  6. 报错:Program bash is not found in PATH

    (如果按照我的方法来的话是没有这个错误的,我之前用别的方法的时候有但是后来还是没解决,写出来放到这里做参考吧) 参考原文:http://blog.csdn.net/fuyongbing1986/art ...

  7. 【MFC】将当前的日期转化为1970年开始的秒计数

    CTime time1 = CTime::GetCurrentTime(); int nTSeconds = time1.GetTime(); CTime time2(,,,,,); nTSecond ...

  8. Oracle添加自增长字段方法步骤

    第一步:创建自增长序列 CREATE SEQUENCE ZH_ALARM_INFO_SEQ--自动增长列 INCREMENT BY 1 -- 每次加几个 START WITH 1 -- 从1开始计数 ...

  9. System Center Configuration Manager 2016 必要条件准备篇(Part1)

    步骤4.创建系统管理容器 SCCM 2016 配置管理系列(Part 1- 4) 介绍AD01上配置了Active Directory域服务(ADDS),然后将Configuration Manag ...

  10. 安装percona工具包

    1.安装percona源 sudo yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona- ...