Nowcoder 2020 Multi University Training Contest 3-A


Problem

Portal


Thoughts



Accepted Code

const int N = 2000010;

int T, n;
char op[N];

signed main()
{
#ifdef duipai
    freopen("E:\\Computer major\\Algorithm competition\\duipai\\in.txt","r",stdin);
    freopen("E:\\Computer major\\Algorithm competition\\duipai\\out1.txt","w",stdout);
#endif

    read >> T;
    while(T -- )
    {
        read >> n;
        read >> op;

        ll cnt = 0, res = 0;
        for(int i = 0 ; i < n ; i ++ )
        {
            if(op[i] == '0') 
            {
                if(cnt) res ++ , cnt -- ; // !!! if语句不能连写成if(op[i] == '0') if(cnt) res ++ , cnt -- ; 
            }
            else if(op[i] == '1') cnt ++ ;
            else if(op[i] == '2') res ++ ;
            else if(op[i] == '3') res ++ ;
        }

        if(cnt) res += cnt / 2;

        write << res << endl;
    }

    return 0;
}

Author: Mrhh
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Mrhh !
评论
 Previous
Nowcoder 2020 Multi University Training Contest 3-C Nowcoder 2020 Multi University Training Contest 3-C
ProblemPortal Thoughts 观察图形边长9,8唯一且相连的特征 先判断给出多边形的点的顺序是顺时针还是逆时针,然后看边长中9,8两条边是否相邻,如果顺时针9,8相邻为左手,否则为右手,如果是逆时针9,8相邻为右手,否则为
Next 
Nowcoder 2020 Multi University Training Contest 2-F Nowcoder 2020 Multi University Training Contest 2-F
ProblemPortal Brute force Code最坏$O(3.9*10^{13})$,题目给的三秒也就$3*10^{8}$次运算。 const int N = 5010; int n, m, k; int g[N][N];
  TOC