POJ 2586:Y2K Accounting Bug(貪心)

來源:互聯網
上載者:User

標籤:poj

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 237375 743200000 8496942500000 8000000

Sample Output

11628300612Deficit

題意是:

對於每一個月來說,不是盈利,就是虧損,如果是盈利則盈利S,如果虧空則虧d。每五個月進行一次統計,共統計八次(1-5月一次,2-6月一次.......8-12月一次)統計的結果是這八次都是虧空。問題:判斷全年是否能盈利,如果能則求出最大的盈利。如果不能盈利則輸出Deficit

貪心思想:每五個連續的月一定虧損,也就是不能出現連續5個月盈利,我們可以設每五個月虧損月數最少為x,這種情況下,如果x能保證讓這五個月為虧損,這是滿足題意的盈利最大值!(比x大的,盈利也少了,題意是讓求最大利潤),x只能為1,2,3,4,5.當然x=5時, 則一定虧空。。除了則之後,也就只有四種情況
ssssd ssssd sssssdd sssdd ssssddd ssddd sssdddd sdddd sd

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<sstream>#include<cmath>using namespace std;#define M 100500int 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;}






聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.