zoukankan      html  css  js  c++  java
  • POJ:2586-Y2K Accounting Bug

    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”。

    • 这个题就是欺负你英语不好读不懂题意,其实还是很简单的只要每次猜中总结亏损都亏损在连续五个月中的后面几个月就好,这样可以让亏损在12个月中分布均匀,符合每五个月都亏损的情况,具体情况如下:

      • ssssd,sssdd,ssddd,sdddd,ddddd

    丑代码:

    #include<stdio.h>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int Max,s,d;
    bool flag;
    
    void check_times(int k)
    {
        int y = 5-k;
        if(k*d - y*s <= 0)
            return ;
        flag = true;
        if(k == 1)
            k = 2,y = 10;
        else if(k == 2)
            k = 4,y = 8;
        else if(k == 3)
            k = 6,y = 6;
        else if(k == 4)
            k = 9, y = 3;
        else if(k == 5)
            k = 12,y = 0;
        int ans = y*s - k*d;
        Max = max(ans,Max);
    }
    
    int main()
    {
        while(scanf("%d%d",&s,&d) != EOF)
        {
            Max = -10000000;
            flag = false;
            for(int i=1;i<=5;i++)
                check_times(i);
            if(!flag || Max < 0)
                printf("Deficit
    ");
            else
                printf("%d
    ",Max);
        }
        return 0;
    }
  • 相关阅读:
    MariaDB的安装与启动
    Win10系统提示对于目标文件系统过大
    kvm中重命名虚拟机
    libvirt启动报错Failed to start Virtualization daemon
    常用的一些开源小工具 之 日期时间类
    常用的一些开源小工具 之 StringUtils
    zookeeper之 watch机制(三)
    shiro权限框架使用详解
    zookeeper节点之 java操作 和zookeeper-权限(ACL),设置超级用户(二)
    时间处理Date,最好改成 LocalDateTime ,时间计算,格式化时间,增加减少时间
  • 原文地址:https://www.cnblogs.com/GoldenFingers/p/9107238.html
Copyright © 2011-2022 走看看