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

POJ 2586:Y2K Accounting Bug(貪心)

系統 2816 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條評論
主站蜘蛛池模板: 绩溪县| 台北县| 通化市| 江山市| 称多县| 清远市| 都江堰市| 瑞丽市| 宜君县| 岳阳市| 大洼县| 沁水县| 阳春市| 濉溪县| 雅安市| 凉城县| 黄石市| 彰化市| 鹤岗市| 洪雅县| 阳泉市| 建阳市| 电白县| 胶州市| 南岸区| 九寨沟县| 江达县| 舟曲县| 玛纳斯县| 曲水县| 开封县| 长乐市| 尚义县| 白河县| 革吉县| 连云港市| 阿尔山市| 白银市| 西乡县| 泉州市| 黄陵县|