zoukankan      html  css  js  c++  java
  • 【玲珑杯R7 A】Boring Game

    Submissions:587Solved:182

    DESCRIPTION
    In a mysterious cave, PigVan ( Mr.Van’s pet ) has lived for thousands years. PigVan absorbed the power of nature, and it may pretend a human in speaking, walking and so on.

    One day, he bought some valuable stone, and divided them into n piles of stone where the ith pile (1≤i≤n) contains values ai .

    After PigVan put them in a line, he wants to play a game.

    In the boring game, he can do this operation:

    Choose a stone pile ai (i>1)and its two adjacent piles ai-1, ai+1, turn (ai-1, ai, ai+1) to (ai-1 + ai, -ai, ai + ai+1).

    PigVan wonders whether he can get (b1, b2, b3, …, bn) after several operations.

    Note:

    If you choose the last pile an, the operation will be ( an-1 + an, -an ) .

    INPUT
    The first line is a single integer
    T
    T, indicating the number of test cases.

    For each test case:

    In the first line, there are only one integer
    n
    n(n≤105), indicating the number of food piles.

    The second line is
    n
    n integers indicate sequence
    a
    a ( | ai | ≤ 106).

    The third line is
    n
    n integers indicate sequence
    b
    b ( | bi | ≤ 106).
    OUTPUT
    For each test case, just print ‘Yes’ if PigVan can get
    b
    b after some operations; otherwise, print ‘No’.
    SAMPLE INPUT
    2
    6
    1 6 9 4 2 0
    7 -6 19 2 -6 6
    4
    1 2 3 4
    4 2 1 3
    SAMPLE OUTPUT
    Yes
    No

    【题目链接】:http://www.ifrog.cc/acm/problem/1071?contest=1009&no=0

    【题解】

    对第i个位置进行操作的话
    假设为
    a[i-1],a[i],a[i+1]
    则变为
    a[i-1]+a[i],-a[i],a[i]+a[i+1];
    可以看一下前缀和

    s[i-1],s[i],s[i+1]
    变成了
    s[i],s[i-1],s[i+1];
    即每次操作只会交换相邻的两个数位置的前缀和;
    则处理出a数组的前缀和和b数组的前缀和
    看看它们所含的元素、以及元素的个数是否相等(集合的相等)
    这个用multiset就能搞;当然用map也行。
    或者排个序判断;

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%lld",&x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int MAXN = 1e5+100;
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    
    int T,n;
    LL sum1[MAXN],sum2[MAXN],x;
    multiset <LL> myset;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        rei(T);
        while (T--)
        {
            myset.clear();
            rei(n);
            rep1(i,1,n)
            {
                rel(x);
                sum1[i] = sum1[i-1]+x;
                myset.insert(sum1[i]);
            }
            rep1(i,1,n)
            {
                rel(x);
                sum2[i] = sum2[i-1]+x;
                __typeof(myset.begin()) bo = myset.find(sum2[i]);
                if (bo!=myset.end())
                    myset.erase(bo);
            }
            if (!myset.empty())
                puts("No");
            else
                puts("Yes");
        }
        return 0;
    }
  • 相关阅读:
    解决Maven下载速度缓慢问题
    IntelliJ IDEA 最新激活码
    Googel 浏览器 模拟发送请求工具--Advanced REST Client
    Firefox火狐 浏览器接口调试工具 JSON 格式化
    修复/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory问题
    解决Nginx: [error] open() "/usr/local/Nginx/logs/Nginx.pid
    configure: error: You need a C++ compiler for C++ support.[系统缺少c++环境]
    解决编译apache出现的问题:configure: error: APR not found . Please read the documentation
    centos6 Linux安装redis 2.6.14
    Nginx+Tomcat负载均衡配置
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626776.html
Copyright © 2011-2022 走看看