zoukankan      html  css  js  c++  java
  • 「日常训练」Alena And The Heater (CFR466D2D)

    题意(Codeforces 940D)

    根据给定要求构建数列,求能构建出相同数列的lr

    分析

    这题写的是真的烦。一定要想到对b串要按照5个5个的看!为什么5个5个的看?因为根据题意,是先看前4个再对最后的0/1做判断。所以只需要考虑四种模式:“00000”“00001”“11110”“11111”。对于“11110”和“00001”很好思考,但我是在“11111”和“00000”卡了一会。想一想(对11111),如果“bi=0 if ai,ai1,ai2,ai3,ai4>r”这个条件不满足,说明这里的ai,...,ai4存在一个小于等于r的。为了使这个条件成立,r的最小值要不小于ai,...的最小值。这样,我不管怎么取r,都能满足11111在这里被生成的特性。对00000,同理。
    同样地,这里也就两个坑。之后取最小l和最大r即可。

    代码

    #include<bits/stdc++.h>
    
    #define inf 0x3f3f3f3f
    #define PB push_back
    #define MP make_pair
    #define fi first
    #define se second
    #define lowbit(x) (x&(-x))
    #define rep(i, a, b) for(int i = (a); i <= (b); i++)
    #define per(i, a, b) for(int i = (a); i >= (b); i--)
    #define pr(x) cout << #x << " = " << x << " ";
    #define prl(x) cout << #x << " = " << x << endl;
    #define ZERO(X) memset((X),0,sizeof(X))
    #define ALL(X) X.begin(),X.end()
    #define SZ(x) (int)x.size()
    
    using namespace std;
    
    typedef pair<int,int> PI;
    typedef pair<pair<int,int>, int> PII;
    typedef pair<pair<pair<int,int>, int>, int> PIII; 
    typedef unsigned long long ull;
    typedef long long ll;
    typedef long double lb;
    #define quickio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
    #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
    /*      debug("Precalc: %.3f
    ", (double)(clock()) / CLOCKS_PER_SEC);
    clock_t z = clock();
            solve();
            //debug("Test: %.3f
    ", (double)(clock() - z) / CLOCKS_PER_SEC);
    */
    template<typename T = int>
    inline T read() {
        T val=0, sign=1;
        char ch;
        for (ch=getchar();ch<'0'||ch>'9';ch=getchar())
            if (ch=='-') sign=-1;
        for (;ch>='0'&&ch<='9';ch=getchar())
            val=val*10+ch-'0';
        return sign*val;
    }
    int n; vector<int> a,b;
    //题解
    int main()
    {
        cin>>n;
        int minl=-1e9,maxl=1e9,minr=-1e9,maxr=1e9,tmp;
        a.PB(0); b.PB(0);
        rep(i,1,n)
        {
            cin>>tmp; a.PB(tmp);
        }
        string str; cin>>str;
        for(int i=5;i<=n;++i)
        {
            string tmp=str.substr(i-5,5);
            int tmpval=a[i-4];
            if(tmp=="11110")
            {
                for(int j=i-4;j<=i;++j) tmpval=min(a[j],tmpval);
                maxr=min(tmpval-1,maxr);
            }
            else if(tmp=="11111")
            {
                for(int j=i-4;j<=i;++j) tmpval=min(a[j],tmpval);
                minr=max(tmpval,minr);
            }
            else if(tmp=="00000")
            {
                for(int j=i-4;j<=i;++j) tmpval=max(a[j],tmpval);
                maxl=min(tmpval,maxl);
    
            }
            else if(tmp=="00001")
            {
                //cout<<"WoW!"<<endl;
                for(int j=i-4;j<=i;++j) tmpval=max(a[j],tmpval);
                //cout<<tmpval<<endl;
                minl=max(tmpval+1,minl);
            }
        }
        cout<<minl<<" "<<maxr<<endl;
        return 0;
    }
    如非注明,原创内容遵循GFDLv1.3发布;其中的代码遵循GPLv3发布。
  • 相关阅读:
    [Tips]git cannot lock ref
    [BUG]Git Sever搭建与相关错误处理
    [Tips]matplotlib 命令行画图保存
    [Tips]Torch功能点记录
    5G元年教育产业再出发 科技赋能的“风口与风险”仍待明晰
    Adobe逆天AI黑科技:美颜照克星,秒还原PS照片
    计算机算法能听声音绘制人脸
    2019 CESA,智能座舱越来越“懂你”
    谷歌首席决策科学家:AI难免犯错,唯有人类可以悬崖勒马
    百度:如何将AI进行到底?
  • 原文地址:https://www.cnblogs.com/samhx/p/9652085.html
Copyright © 2011-2022 走看看