Y2K Accounting Bug
 

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 题目大意:微软公司的12个月的盈利情况,已知每月若盈利,则固定为s元;若亏损,则固定为d元。在保证每个连续的五个月都是亏损的情况下,判断是否可以全年盈利,若盈利,输出最大盈利额,反之,输出Deficit
解题思路:贪心的思想,保证每个连续5个月亏损最少即可。
     eg: s=59 d=237 那么连续五个月中 4个月盈利,一个月亏损时连续亏损最小,为-1;
     假设[1,5]表示一月到五月的总亏损,保证[1,5]=-1,那么[2,6]要想同样最小 六月的盈亏情况应与一月相同。
     同理:七月与二月相同,八月与三月相同。显然六到十月份的盈亏状态应同一月到五月的。
     显然:十一月与十二月 分别对应 一月和二月。
这里设盈利为1,亏损为0 [1-5]=11110||10111||11011.... 要想最大盈利,要保证最后两个月尽量盈利,及保证一月二月最大盈利,故前五个月应保证盈利月在前。
Code:
 #include<stdio.h>
int main()
{
int s,d,sum,cnt;
while (scanf("%d %d",&s,&d)!=EOF)
{
sum=s*;
cnt=;
while (sum>=)
{
sum-=d+s;
cnt++;
}
sum=(s*(-cnt)-cnt*d)*;//前十个月的总盈亏
if (cnt==) {sum+=s;sum-=d;}//判断最后两月的盈亏状况
else if (cnt==) sum-=*d;
else sum+=*s;
if (sum>) printf("%d\n",sum);//sum<0 说明亏损
else printf("Deficit\n");
}
return ;
}

POJ2586——Y2K Accounting Bug的更多相关文章

  1. [POJ2586]Y2K Accounting Bug

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

  2. poj2586 Y2K Accounting Bug(贪心)

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

  3. POJ2586 Y2K Accounting Bug 解题报告

    Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vi ...

  4. POJ-2586 Y2K Accounting Bug贪心,区间盈利

    题目链接: https://vjudge.net/problem/POJ-2586 题目大意: MS公司(我猜是微软)遇到了千年虫的问题,导致数据大量数据丢失.比如财务报表.现在知道这个奇特的公司每个 ...

  5. POJ2586 Y2K Accounting Bug(贪心)

    题目链接. 题目大意: 题目相当晦涩难懂啊. 一年的12个月,每5个月统计一次,如从1~5,2~6,3~7,...,8~12共统计了8次,已知每次都deficit,问这一年有没有盈利的可能. 一个月s ...

  6. poj2586 Y2K Accounting Bug —— 枚举

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

  7. Y2K Accounting Bug(贪心)

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

  8. 贪心 POJ 2586 Y2K Accounting Bug

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

  9. Y2K Accounting Bug 分类: POJ 2015-06-16 16:55 14人阅读 评论(0) 收藏

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11222   Accepted: 56 ...

随机推荐

  1. TransparentBlt函数的使用注意事项

    今天客户需要在软件上需要添加一个自己公司的Logo,要求使用镂空透明的形式展现,本来以为很简单的工作没想到在MFC下这么复杂.Logo为BMP格式,白色背景. 以为和在按钮上显示控件差不多,先导入BI ...

  2. windbg远程调试

    1, A,调试机. B,被调试机. 2, 在B机上安装windbg,公共符号文件,程序的PDB都要复制过来. 公共符号文件位置设置在于A机相同的位置. windbg–server tcp:port=5 ...

  3. 专家解说IT行业存在哪些安全风险

    本人为原创作品:e良师益友 ,转载是并且注明 网络带动了IT行业的发展,同时也带来了安全风险,国外的专家分析2014年IT行业存在的11个安全隐患,随着越来越多技术的不断开发,为方便人们记忆账号,产生 ...

  4. 2014-10 u-boot 顶层config.mk分析

    /** ****************************************************************************** * @author    Maox ...

  5. PHP 魔术方法(所有的魔术方法)

    慢慢长寻夜,明月高空挂. 目前PHP所有的魔术方法有一下这些 __construct() __destruct() __call() __callStatic() __get() __set() __ ...

  6. Thinkphp 缓存微信jssdk相关认证参数

    public function getapiSignature() {  $access_token=S('access_token');  //先查询缓存中是否存在  if($access_toke ...

  7. jooml二次开发---添加文章组件

    在写一个joomla组件的时候需要手动添加excel表格,并把表格当做文章的内容添加到前台文章中, 开始不知道怎么下手,索性先把一个基本的组件写出来,在joomla网站上测试是可以访问这个组件的,在p ...

  8. Python+PyQt 数据库基本操作

    Sqlite: 使用Python的sqlite3: 需要注意下commit方式与qt稍有不同 import sqlite3 class DBManager(): def __init__(self): ...

  9. UartDma工作方式

    一.初始化 1.初始化串口,时钟 MX_USART1_UART_Init(); 串口时钟初始化为内部时钟 PeriphClkInit.Usart1ClockSelection = RCC_USART1 ...

  10. 详解Javascript中的Array对象

    基础介绍 创建数组 和Object对象一样,创建Array也有2种方式:构造函数.字面量法. 构造函数创建 使用构造函数的方式可以通过new关键字来声明,如下所示: 12 var arr = new ...