zoukankan      html  css  js  c++  java
  • Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1)

    D1. Great Vova Wall (Version 1)
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.

    The current state of the wall can be respresented by a sequence aa of nn integers, with aiai being the height of the ii -th part of the wall.

    Vova can only use 2×12×1 bricks to put in the wall (he has infinite supply of them, however).

    Vova can put bricks horizontally on the neighboring parts of the wall of equal height. It means that if for some ii the current height of part ii is the same as for part i+1i+1 , then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 11 of the wall or to the right of part nn of it).

    The next paragraph is specific to the version 1 of the problem.

    Vova can also put bricks vertically. That means increasing height of any part of the wall by 2.

    Vova is a perfectionist, so he considers the wall completed when:

    • all parts of the wall has the same height;
    • the wall has no empty spaces inside it.

    Can Vova complete the wall using any amount of bricks (possibly zero)?

    Input

    The first line contains a single integer nn (1n21051≤n≤2⋅105 ) — the number of parts in the wall.

    The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1091≤ai≤109 ) — the initial heights of the parts of the wall.

    Output

    Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).

    Print "NO" otherwise.

    Examples
    Input
    Copy
    5
    2 1 1 2 5
    
    Output
    Copy
    YES
    
    Input
    Copy
    3
    4 5 3
    
    Output
    Copy
    YES
    
    Input
    Copy
    2
    10 10
    
    Output
    Copy
    YES
    
    Input
    Copy
    3
    1 2 3
    
    Output
    Copy
    NO
    
    Note

    In the first example Vova can put a brick on parts 2 and 3 to make the wall [2,2,2,2,5][2,2,2,2,5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5,5,5,5,5][5,5,5,5,5] .

    In the second example Vova can put a brick vertically on part 3 to make the wall [4,5,5][4,5,5] , then horizontally on parts 2 and 3 to make it [4,6,6][4,6,6] and then vertically on part 1 to make it [6,6,6][6,6,6] .

    In the third example the wall is already complete.

    题意

      给出一组数,可以让连续的两个同时加一,也可以让一个数加二,能否用这两种操作使得最后数组的数相同。

    分析

      用栈一个一个判断就行了,如果栈顶元素和当前数字相同就可以变成比它们大的任意数,如果栈顶元素和当前数组差二的倍数,也可以变成比两个中大的任意数。

    ///  author:Kissheart  ///
    #include<stdio.h>
    #include<algorithm>
    #include<iostream>
    #include<string.h>
    #include<vector>
    #include<stdlib.h>
    #include<math.h>
    #include<queue>
    #include<deque>
    #include<ctype.h>
    #include<map>
    #include<set>
    #include<stack>
    #include<string>
    #define INF 0x3f3f3f3f
    #define FAST_IO ios::sync_with_stdio(false)
    const double PI = acos(-1.0);
    const double eps = 1e-6;
    const int MAX=2e5+10;
    const int mod=1e9+7;
    typedef long long ll;
    using namespace std;
    #define gcd(a,b) __gcd(a,b)
    inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
    inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
    inline ll inv1(ll b){return qpow(b,mod-2);}
    inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
    inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
    //freopen( "in.txt" , "r" , stdin );
    //freopen( "data.txt" , "w" , stdout );
    stack<int>s;
    int n;
    int a[MAX];
    int main()
    {
        while(!s.empty()) s.pop();
    
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
    
        for(int i=1;i<=n;i++)
        {
            if(s.empty())
            {
                s.push(a[i]);
                continue;
            }
            //printf("%d %d
    ",s.top(),a[i]);
            if(s.top()==a[i])
                s.pop();
            else if(abs(s.top()-a[i])%2==0)
                s.pop();
            else
                s.push(a[i]);
        }
        if(!s.empty())
            s.pop();
        
        if(s.empty()) printf("YES
    ");
        else printf("NO
    ");
        return 0;
    }
    View Code
  • 相关阅读:
    知识点:Mysql 索引优化实战(3)
    知识点:Mysql 索引原理完全手册(2)
    知识点:Mysql 索引原理完全手册(1)
    大数据体系:数据分析体系总图
    数据化分析:微信文章不增粉的主要原因
    提问:MicrosoftUnderlying input stream returned zero bytes
    优化:更优雅的异步代码?
    涨姿势:Mysql 性能优化完全手册
    总结:Java 集合进阶精讲1
    冷知识点:COLLATE 关键字是什么意思?
  • 原文地址:https://www.cnblogs.com/Kissheart/p/10156384.html
Copyright © 2011-2022 走看看