POJ 2586:Y2K Accounting Bug(贪心)


Y2K Accounting Bug

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;
}






优质内容筛选与推荐>>
1、20+最好的网页注释和标记工具
2、初探Object Pascal的类(三)
3、捕捉页面与下载图片
4、Wince驱动结构分析
5、ASP.NET程序中常用的三十三种代码


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn