日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

POJ 2586:Y2K Accounting Bug(貪心)

系統(tǒng) 2611 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

      
    

題意是:

      
        對(duì)于每個(gè)月來(lái)說(shuō),不是盈利,就是虧損,假設(shè)是盈利則盈利S,假設(shè)虧空則虧d。
每五個(gè)月進(jìn)行一次統(tǒng)計(jì),共統(tǒng)計(jì)八次(1-5月一次,2-6月一次.......8-12月一次)
統(tǒng)計(jì)的結(jié)果是這八次都是虧空。
問(wèn)題:推斷全年能否盈利,假設(shè)能則求出最大的盈利。
假設(shè)不能盈利則輸出Deficit
      
    

      貪心思想:
每五個(gè)連續(xù)的月一定虧損,也就是不能出現(xiàn)連續(xù)5個(gè)月盈利,我們能夠設(shè)每五個(gè)月虧損月數(shù)最少為x,這樣的情況下,

假設(shè)x能保證讓這五個(gè)月為虧損,這是滿足題意的盈利最大值!

(比x大的,盈利也少了,題意是讓求最大利潤(rùn)),x僅僅能為1,2,3,4,5.

當(dāng)然x=5時(shí), 則一定虧空。。

除了則之后,也就僅僅有四種情況
      
        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(貪心)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 芦溪县| 海晏县| 中卫市| 周宁县| 木兰县| 闽侯县| 海林市| 桐乡市| 武夷山市| 建平县| 瑞金市| 夏河县| 鲁甸县| 昭平县| 南皮县| 稷山县| 姚安县| 乐清市| 桃园市| 怀宁县| 天水市| 绥宁县| 偏关县| 新干县| 日照市| 南部县| 汽车| 浮山县| 辉南县| 于都县| 滨海县| 怀宁县| 金山区| 鄂伦春自治旗| 曲阜市| 嘉鱼县| 福州市| 伊春市| 台湾省| 永川市| 确山县|