Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 10024 |
|
Accepted: 4990 |
Description
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
Output
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; }
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
