POJ 2586 水贪心。

Y2K Accounting Bug
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 9260 Accepted: 4605

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代表每月的亏损然后让你求该年能够盈利的最大利润
是多少。
思路:贪心。首先考虑头5个月的,那么只有5种情况,而且亏损的月份越晚越好,而且前五个月要亏损一共有五种情况,4S1D 3S2D 2S3D 1S4D 5D。
      再次为什么亏损的月份越靠后越好呢,我们拿4S1D的情况来看,如果前五个月是SSSSD,那么要使得全年有可能盈利2-6月也必须是4S1D的形式(2-5月已经确定是SSSD了,
      所以要使得全年利润最大,那么六月必然得是S的形式,依次类推推下去那么结果就是SSSSDSSSSDSS的情况。
      我们再来看第一个月亏损的4S1D的情况 DSSSS按照上述可以推得 DSSSSDSSS但是我们发现十一月和十二月不能同时为S否则会出现SSSSS的情况与题目意思不符合,所以只
      可能是DSSSSDSSSSDS的情况相比第一种情况少了个S,故盈利金额肯定小于第一种,同理把D放在2 3 4月一样推。
      那么4S1D的情况满足,后面的其他情况也都满足,所以我们不难发现,五个月一个循环也就是6-10月的跟1-5月的完全相同,11 12月的跟1 2月的完全相同才会有最大收益
      那么一共会出现五种情况:
      SSSSDSSSSDSS,SSSDDSSSDDSS,SSDDDSSDDDSS,SDDDDSDDDDSD,DDDDDDDDDDDD。统计金额再判断下就O了- -。~

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
   int s,d;
   while(cin>>s>>d)
   {   int ans;
       if(4*s<d)
       {
          ans=10*s-2*d;
       }
       else
        if(3*s<2*d)
       {
          ans=8*s-4*d;
       }
       else
       if(2*s<3*d)
       {
           ans=6*s-6*d;
       }
       else
        if(s<4*d)
       {
           ans=3*s-9*d;
       }
      else
       {
           ans=-12*d;
       }
       if(ans>0)
        cout<<ans<<endl;
       else
        cout<<"Deficit"<<endl;
   }


    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值