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

    开始看这题的时候,看了半小时没看懂到底要干嘛,不得不说英语太差了,后来别人说了一下题意,大致是这样
    该公司某个月要么亏损d,要么盈利s,但是每连续5个月必须是亏损的(1-5,2-6,3-7,4-8,5-9,6-10,7-11,8-12)
    但还是没有思路。。。。
    参考思路:5个月总额必须亏损,但要盈利最大,所以尽量把d放后面
    假如4个月盈利,一个月亏,即ssssd 可以推出情况  ssssdssssdss  所以总的钱为sum=10*s-2*d,如果sum大于0就输出sum否则输出Deficit
    同理3个月盈利,2个月亏损,即sssddsssddss  sum=8*s-4*d,如果sum大于0就输出sum否则输出Deficit.
    ............
    Y2K Accounting Bug
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 8484   Accepted: 4190

    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
    

    Source

    #include<stdio.h>
    int main()
    {
         int s,d,ans;
         while(scanf("%d %d",&s,&d)!=EOF)
         {
              if(4*s-d<=0)
               ans=10*s-2*d;
               else if(3*s-2*d<=0)
               ans=8*s-4*d;
               else if(2*s-3*d<=0)
               ans=6*s-6*d;
               else if(s-4*d<=0)
               ans=3*s-9*d;
               else
               ans=0-5*d;
               if(ans>0)
               printf("%d
    ",ans);
               else
               printf("Deficit
    ");
         }
         return 0;
    }
    View Code
  • 相关阅读:
    Java中的数据类型
    SSE2 Intrinsics各函数介绍[转]
    mac terminal的使用技巧
    vi打开二进制文件
    svn
    fitness
    <正见>摘抄
    管理自己
    [C++程序设计]基于对象的程序设计 基于对象的程序设计
    [C++程序设计]引用
  • 原文地址:https://www.cnblogs.com/llei1573/p/3207409.html
Copyright © 2011-2022 走看看