POJ 2586:Y2K Accounting Bug(贪心)

系统 2270 0

Time Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 10024
Accepted: 4990

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

      
    

题意是:

      
        对于每个月来说,不是盈利,就是亏损,假设是盈利则盈利S,假设亏空则亏d。
每五个月进行一次统计,共统计八次(1-5月一次,2-6月一次.......8-12月一次)
统计的结果是这八次都是亏空。
问题:推断全年能否盈利,假设能则求出最大的盈利。
假设不能盈利则输出Deficit
      
    

      贪心思想:
每五个连续的月一定亏损,也就是不能出现连续5个月盈利,我们能够设每五个月亏损月数最少为x,这样的情况下,

假设x能保证让这五个月为亏损,这是满足题意的盈利最大值!

(比x大的,盈利也少了,题意是让求最大利润),x仅仅能为1,2,3,4,5.

当然x=5时, 则一定亏空。。

除了则之后,也就仅仅有四种情况
      
        ssssd ssssd ss
sssdd sssdd ss
ssddd ssddd ss
sdddd sdddd sd
      

      

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath>

using namespace std;

#define M 100500

int main()
{
    int s, d;
    while(~scanf("%d%d", &s, &d))
    {
        if(s>4*d)
        {
            printf("Deficit\n");
            continue;
        }
        int t = 1;
        while(s*(5-t)>d*t)
            t++;
        int k;
        if(t==4)
            k = 2*t+1;
        else
            k = 2*t;
        int ans = s * (12-k) - d*k;
        if(ans>0)
            printf("%d\n", ans);
        else
            printf("Deficit\n");
    }
    return 0;
}

    






POJ 2586:Y2K Accounting Bug(贪心)


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论