zoukankan      html  css  js  c++  java
  • Y2K Accounting Bug

    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
    
    这个题是说
    有一家公司,每5个月的总营业额必然是亏损的,每组两个数据a,b是每月可能盈利的钱,或者亏损的钱,12个月都一样
    问: 满足每5个月的总营业额必然是亏损的条件,这家公司是赚钱还是亏损,
    赚钱:输出金额;
    亏损:输出Deficit
    分析的话
    12个月可能是以下情况
     
    1 2 3 4 5 6 7 8 9 10 11 12 
    s s s s d s s s s d  s  s //每5个月里只有1个月亏损 
    s s s d d s s s d d  s  s //每5个月里只有2个月亏损 
    s s d d d s s d d d  s  s //每5个月里只有3个月亏损 
    s d d d d s d d d d  s  d //每5个月里只有4个月亏损 
     
    所以  代码是
    #include<stdio.h>
    int main()
    {
        int a,b,t;
        while(~scanf("%d %d",&a,&b))
        {
            if(4*a-b<0) t=10*a-2*b;
            else if(3*a-2*b<0) t=8*a-4*b;
            else if(2*a-3*b<0) t=6*a-6*b;
            else if(a-4*b<0) t=3*a-9*b;
            else t=-1;
            if(t>0) printf("%d
    ",t);
            else printf("Deficit
    ");
        }
        return 0;
    }
  • 相关阅读:
    Spring IoC 容器和 AOP
    MySQL 锁与事务控制
    MySQL 存储引擎的选择
    如何理解MySQL 索引最左前缀原则
    MySQL 索引
    Java 线程池
    Java多线程 ReentrantLock、Condition 实现生产者、消费者协作模式
    Java多线程并发中 CAS 的使用与理解
    Java多线程中协作机制
    Mysql-SQL生命周期-show profile
  • 原文地址:https://www.cnblogs.com/kongkaikai/p/3241811.html
Copyright © 2011-2022 走看看