zoukankan      html  css  js  c++  java
  • POJ-2586 Y2K Accounting Bug 贪心

    https://vjudge.net/problem/POJ-2586

    题意(这题意真难懂。。。)

    已知一个公司在某一年中,每个月要么固定盈利s、要么固定亏损d。但是具体哪个月盈利、那个月亏损却不得而知。不过可以肯定的是,这一年中,任意的连续5个月盈亏和必定是亏损(< 0)。 问这年是否存在盈利的可能,若可能盈利,最大的盈利额是多少? 

    分析

    贪心来搞,先假设所有月都是盈利的。然后每连续五个月进行检查,如果不符合要,则在末尾把盈利的改为亏损,就这样逐次检查修改直到符合条件。最后再计算总和,看是否盈利即可。

    #include<iostream>
    #include<cmath>
    #include<cstring>
    #include<queue>
    #include<vector>
    #include<cstdio>
    #include<algorithm>
    #include<map>
    #include<set>
    
    #define rep(i,e) for(int i=0;i<(e);i++)
    #define rep1(i,e) for(int i=1;i<=(e);i++)
    #define repx(i,x,e) for(int i=(x);i<=(e);i++)
    #define X first
    #define Y second
    #define PB push_back
    #define MP make_pair
    #define mset(var,val) memset(var,val,sizeof(var))
    #define scd(a) scanf("%d",&a)
    #define scdd(a,b) scanf("%d%d",&a,&b)
    #define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
    #define pd(a) printf("%d
    ",a)
    #define scl(a) scanf("%lld",&a)
    #define scll(a,b) scanf("%lld%lld",&a,&b)
    #define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
    #define IOS ios::sync_with_stdio(false);cin.tie(0)
    
    using namespace std;
    typedef long long ll;
    template <class T>
    void test(T a){cout<<a<<endl;}
    template <class T,class T2>
    void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
    template <class T,class T2,class T3>
    void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}
    template <class T>
    inline bool scan_d(T &ret){
        char c;int sgn;
        if(c=getchar(),c==EOF) return 0;
        while(c!='-'&&(c<'0'||c>'9')) c=getchar();
        sgn=(c=='-')?-1:1;
        ret=(c=='-')?0:(c-'0');
        while(c=getchar(),c>='0'&&c<='9') ret = ret*10+(c-'0');
        ret*=sgn;
        return 1;
    }
    const int N = 1e6+10;
    const int inf = 0x3f3f3f3f;
    const ll INF = 0x3f3f3f3f3f3f3f3fll;
    const ll mod = 1000000000;
    int T;
    
    void testcase(){
        printf("Case %d:",++T);
    }
    
    const int MAXN = 5e5+10 ;
    const int MAXM = 150;
    const double eps = 1e-8;
    const double PI = acos(-1.0);
    
    int a[15];
    bool check(int i){
        int sum=0;
        for(int j=1;j<=5;j++){
            sum+=a[i+j];
        }
        return sum>=0;
    }
    void work(){
        int s,d;
        while(cin>>s>>d){
            for(int i=1;i<=12;i++) a[i]=s;
    
            for(int i=0;i<8;i++){
                for(int j=0;j<5;j++){
                    if(check(i)){
                        a[i+5-j]=-d;
                    }else break;
                }
            }
    
            int sum=0;
            for(int i=1;i<=12;i++) sum+=a[i];
    
            if(sum<0) puts("Deficit");
            else cout<<sum<<endl;
        }
    }
    int main() {
    #ifdef LOCAL
        freopen("in.txt","r",stdin);
    #endif // LOCAL
    //    init();
        work();
        return 0;
    }
  • 相关阅读:
    Tensorflow入门:Linear Regression
    日语动词变形总结
    序列模型第二周作业2:Emojify!
    序列模型第二周作业1:Operations on word vectors
    序列模型第一周作业3: Improvise a Jazz Solo with an LSTM Network
    序列模型第一周作业2: Character level language model
    序列模型第一周作业1: Building your Recurrent Neural Network
    Bidirectional RNN (BRNN)
    Long Short term memory unit(LSTM)
    propertyGrid使用
  • 原文地址:https://www.cnblogs.com/fht-litost/p/9180912.html
Copyright © 2011-2022 走看看