poj 2586 Y2K Accounting Bug

原创 2015年11月17日 16:43:50
                                                                                                                           Y2K Accounting Bug
Time Limit: 1000MS   Memory Limit: 65536K
     

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
题意:一个记账系统遭受到了攻击,导致某些数据丢失,我们已知在一年的十二个月中,连续的五个月(例如1~5,2~6,3~7,4~8,5~9,6~10,7~11,8~12) 必定会亏损(即盈利〈亏损)
,现已知盈利s,亏损d,让我们求在这一年中,我们能否盈利,如果能,则输出最大的盈利数,否则输出“Deficit”,该题主要是题意很难读懂,其实做法很简单,考得无非就是
贪心罢了,我们必须要把亏损的那个月最大利用化,这样才有可能出现最大盈利
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
    int a[13],i,sum,j,k;
    int s,d;
    while(cin>>s>>d)
    {
        for(i=1;i<=12;i++)
        {
            a[i]=s;//我们先假设每个月都可以盈利,除去那些亏损的月,这样才可能达到最大盈利
        }
        for(j=1;j<=8;j++)
        {
            sum=0;
            for(k=j;k<=j+4;k++)
            {
                sum+=a[k];//求出连续五个月的收入
            }
            while(sum>=0)//因为题意中,连续的五个月必定亏损,如果连续的五个月的收入大于0,那么我们要把倒着把这五个月中的月份记为亏损,直到收入小于0
            {
                sum-=(s+d);//我们不仅要减掉亏损的钱,还要减去我们假设这个月能够盈利的钱
                a[--k]=d*(-1);//把月份记为亏损
            }
        }
        sum=0;
        for(i=1;i<=12;i++)
        {
            sum+=a[i];
            //cout<<a[i]<<" ";
        }//这时我们已经把可能出现最大盈利的每个月的收入求出来了,只需要求和
        //cout<<endl;
        if(sum>=0)//如果和大于等于0,那么可以出去最大盈利
        {
            cout<<sum<<endl;
        }else{//否则,不可能盈利
            cout<<"Deficit"<<endl;
        }
    }
    return 0;
}

Y2K Accounting Bug POJ2586

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5559...
  • tiantangrenjian
  • tiantangrenjian
  • 2011年09月25日 15:02
  • 3109

** poj Y2K Accounting Bug 2586

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1011...
  • chaoyueziji123
  • chaoyueziji123
  • 2014年07月18日 15:16
  • 892

poj Y2K Accounting Bug 贪心 暑假第五题

许多人说看不出与贪心什么关系,我笑了。 打第一次时思路错了,分析的时候才看出是贪心,是最优子问题; 拿第二组举例吧 375 743 正确的1到5月应该是  375 375 375 -74...
  • sholck222
  • sholck222
  • 2015年07月08日 17:44
  • 379

poj - 2586 - Y2K Accounting Bug

题意:ACM因为Y2K这个bug丢失了MS Inc的一些统计数据,ACM所记得的,那些数据是MS Inc 提交的1999年各个月的盈利或亏损情况,而且,一个月如果是盈利的,那么盈利就为输入的s,如果这...
  • SCNU_Jiechao
  • SCNU_Jiechao
  • 2013年02月17日 22:22
  • 1410

POJ 2586 Y2K Accounting Bug

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9748...
  • u013476556
  • u013476556
  • 2014年06月07日 20:01
  • 522

poj 2586 Y2K Accounting Bug

Y2K Accounting Bug Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub...
  • u013497151
  • u013497151
  • 2014年03月24日 00:30
  • 740

POJ 2586:Y2K Accounting Bug

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1129...
  • u010885899
  • u010885899
  • 2015年07月09日 19:44
  • 999

poj 2586 Y2K Accounting Bug

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9769   Accepte...
  • u014361775
  • u014361775
  • 2014年06月13日 16:58
  • 453

Y2K Accounting Bug POJ 2586

Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vi...
  • Sunmh_AC
  • Sunmh_AC
  • 2015年08月25日 14:48
  • 239

POJ 2586 Y2K Accounting Bug

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10909   Accept...
  • CriminalCode
  • CriminalCode
  • 2015年02月10日 15:02
  • 369
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:poj 2586 Y2K Accounting Bug
举报原因:
原因补充:

(最多只允许输入30个字)