• poj 2586 Y2K Accounting Bug


    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

    大致题意就是有一个年度报告,每五个月为一个季度往上提交报告,一年共上交八次报告。分别为1月-5月,2月-6月,3月-7月,4月-8月,5-9,6-10,7-11,8-12.
    每个季度都是亏损,问一年有可能盈余吗,求最大盈余,若不能盈余则输出“Deficit”。主要采用贪心的思想,把亏损放在每季度的后面。
    输入s和d,s为每月的盈余,d为每月的亏损。

    样例1: 59 237
       SSSSD SSSSD SS
    样例2: 375 743
    SSSDD SSSDD SS

    一共有这么几种情况:

     SSSSD SSSSD SS    一年有2个月为亏损
     SSSDD SSSDD SS   一年有4个月为亏损
     SSDDD SSDDD SS   一年有6个月为亏损

     SDDDD SDDDD SD  一年有9个月为亏损

     DDDDD DDDDD DD 一年有12个月为亏损

    
    
     1 #include <iostream>
     2 #include <cstdio>
     3 using namespace std;
     4 
     5 int main()
     6 {
     7     int s,d;
     8     int a[10]={0,2,4,6,9,12};
     9     while(cin>>s>>d)
    10     {
    11         int k=1;
    12         while(s*(5-k)>d*k)
    13             k++;
    14         int ans=s*(12-a[k])-d*a[k];
    15         if(ans<0)
    16             cout<<"Deficit"<<endl;
    17         else
    18         printf("%d
    ",ans);
    19     }
    20     return 0;
    21 }
    View Code
    
    
    
     
  • 相关阅读:
    NSCoding相关
    object c 运行时编程指南
    iphone 框架体系结构
    Object c 反射
    hook qq 聊天内容(转)
    iphone地址本操作
    通过xib文件创建子控件(转)
    iphone生成唯一字符串
    反射手册笔记 6.NET组件模型
    IDC项目技术总结
  • 原文地址:https://www.cnblogs.com/cxbky/p/4878795.html
Copyright © 2020-2023  润新知