poj 2586 Y2K Accounting Bug【贪心】【刷题计划】

Y2K Accounting Bug

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 16154   Accepted: 8111

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

Source

题意:某公司每5个月公布一次财务报告,一年公布了8次,每一次都是亏损,但是不知道每一次亏损了多少,题目给定了每个月的盈利值s和亏损值d,问,这一年能否不亏损,如果能,最大盈利值是多少?

思路:一开始没有懂什么意思,后来师父解释如下:1~5,2~6,3~7,4~8,5~9,...8~12.共8个季度,每个季度都是亏钱,要求最大的盈利值,就要使全年亏钱的月份最少,盈利月份数最多,并且满足每个季度都是亏损的,我用的枚举方法有如下情况(从盈利最多的情况开始枚举,直到枚举到全年亏损的情况):

1:每个季度4个月盈利,1个月亏。ssssd

2: 每个季度3个月盈利,2个月亏。sssdd

3: 每个季度2个月盈利,3个月亏。ssddd

4:每个季度1个月盈利,4个月亏。sdddd

5: 每个季度都亏损。输出    :Deficit。

#include<stdio.h>
int main()
{
    int s,d;//s是赚的钱,d是亏的钱
    while(scanf("%d%d",&s,&d)!=EOF)
    {
        if(4*s < d&&(10*s-2*d>=0))//每个季度里4个月赚,1个月亏。全年10个月赚,2个月亏。
            printf("%d\n",10*s-2*d);
        else if(3*s < 2*d&&(8*s-4*d>=0))//每个季度3个月赚,2个月亏。之后以此类推。
            printf("%d\n",8*s-4*d);
        else if(2*s < 3*d&&(6*s-6*d>=0))
            printf("%d\n",6*s-6*d);
        else if(s < 4*d&&(3*s-9*d>=0))
            printf("%d\n",3*s-9*d);
        else
            printf("Deficit\n");//以上条件都不满足,说明全年只有亏损
    }
    return 0;
}

思路2:在师父吐槽了我的方法的局限性后,他给我解释了一下他的方法,可以适用更大数据的情况,解释了半天,我都不知道怎么用代码去实现,最后师父亲自写出来我才懂了,泪目~~

全年每个月的盈利情况如下:  1:ssssdssssdss

               2:sssddsssddss

               3:ssdddssdddss

               4:sddddsddddsd

               5:dddddddddddd

#include<stdio.h>
int main()
{
    int s,d,i,n,sum;//s是赚的钱,d是亏的钱
    while(scanf("%d%d",&s,&d)!=EOF)
    {
        n = 5;
        for(i = 4; i >= 0; i --)//每个季度盈利月份从4枚举到0
        {
            if(i*s < (n-i)*d)
                break;
        }//找到满足每个季度亏损并且使全年盈利最多的月份数i
        sum = (i*s-(n-i)*d)*2;//计算在前10个月总的盈利数
        if(i > 2)
            sum += s*2;//当每个季度的盈利月份大于2时,全年剩余的两个月也是盈利
        else
            sum += s*i - d*(2-i);//反之,有可能一个月亏或者最后的两个月都亏损
        if(sum >= 0)
            printf("%d\n",sum);
        else
            printf("Deficit\n");
    }
    return 0;
}
时间: 2024-08-05 05:55:56

poj 2586 Y2K Accounting Bug【贪心】【刷题计划】的相关文章

poj 2586 Y2K Accounting Bug (贪心)

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9632   Accepted: 4806 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc.

POJ 2586 Y2K Accounting Bug(枚举大水题)

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 5344 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc

poj 2586 Y2K Accounting Bug

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10150   Accepted: 5061 题目大意:有家公司每个月有盈余s 和亏损d但不知道具体是那个月 只知道一年中每个连续的五个月都是亏损的.要求求出该公司这一年里最大的盈利的可能金额 若不能盈利就输出Deficit 注意如果s>4d也是要输出Deficit的 可以用分类方法去做 注意要保证每连续的五个月中都有n个d保证这五个月是

POJ 2580 Y2K Accounting Bug 贪心

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10120   Accepted: 5046 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc

[POJ 2586] Y2K Accounting Bug (贪心)

题目链接:http://poj.org/problem?id=2586 题目大意:(真难读懂啊)给你两个数,s,d,意思是MS公司每个月可能赚钱,也可能赔钱,如果赚钱的话,就是赚s元,如果赔钱的话,就是陪d元.现在告诉你只要是连续的5个月,就亏钱(亏多少不知道),问你MS公司全年能够赚多少钱,如果赚不了钱的话,就输出“Deficit” 贪心:我们说,输出的最终结果是f(x,y)=x*s-y*d,也就是说现在要求得x,y使得f(x,y)具有最大值. 当s,d,x+y给定时,x越大,则赚的钱越多.

Poj 2586 / OpenJudge 2586 Y2K Accounting Bug

1.Link: http://poj.org/problem?id=2586 2.Content: Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10520   Accepted: 5257 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some

Y2K Accounting Bug(贪心)

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10945   Accepted: 5499 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc

Y2K Accounting Bug(贪心)

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10687   Accepted: 5349 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc

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. Al