zoukankan      html  css  js  c++  java
  • Kind Anton CodeForces

    Once again, Boris needs the help of Anton in creating a task. This time Anton needs to solve the following problem:

    There are two arrays of integers aa and bb of length nn. It turned out that array aa contains only elements from the set {1,0,1}{−1,0,1}.

    Anton can perform the following sequence of operations any number of times:

    1. Choose any pair of indexes (i,j)(i,j) such that 1i<jn1≤i<j≤n. It is possible to choose the same pair (i,j)(i,j) more than once.
    2. Add aiai to ajaj. In other words, jj-th element of the array becomes equal to ai+ajai+aj.

    For example, if you are given array [1,1,0][1,−1,0], you can transform it only to [1,1,1][1,−1,−1], [1,0,0][1,0,0] and [1,1,1][1,−1,1] by one operation.

    Anton wants to predict if it is possible to apply some number (zero or more) of these operations to the array aa so that it becomes equal to array bb. Can you help him?

    Input

    Each test contains multiple test cases.

    The first line contains the number of test cases tt (1t100001≤t≤10000). The description of the test cases follows.

    The first line of each test case contains a single integer nn (1n1051≤n≤105)  — the length of arrays.

    The second line of each test case contains nn integers a1,a2,,ana1,a2,…,an (1ai1−1≤ai≤1)  — elements of array aa. There can be duplicates among elements.

    The third line of each test case contains nn integers b1,b2,,bnb1,b2,…,bn (109bi109−109≤bi≤109)  — elements of array bb. There can be duplicates among elements.

    It is guaranteed that the sum of nn over all test cases doesn't exceed 105105.

    Output

    For each test case, output one line containing "YES" if it's possible to make arrays aa and bb equal by performing the described operations, or "NO" if it's impossible.

    You can print each letter in any case (upper or lower).

    Example

    Input
    5
    3
    1 -1 0
    1 1 -2
    3
    0 1 1
    0 2 2
    2
    1 0
    1 41
    2
    -1 0
    -1 -41
    5
    0 1 -1 1 -1
    1 1 -1 1 -1
    
    Output
    YES
    NO
    YES
    YES
    NO
    

    Note

    In the first test-case we can choose (i,j)=(2,3)(i,j)=(2,3) twice and after that choose (i,j)=(1,2)(i,j)=(1,2) twice too. These operations will transform [1,1,0][1,1,2][1,1,2][1,−1,0]→[1,−1,−2]→[1,1,−2]

    In the second test case we can't make equal numbers on the second position.

    In the third test case we can choose (i,j)=(1,2)(i,j)=(1,2) 4141 times. The same about the fourth test case.

    In the last lest case, it is impossible to make array aa equal to the array bb.

    //#include <bits/stdc++.h>
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include<cstring>
    #include <algorithm>
    #include <queue>
    #include<map>
    #include<set>
    #include<vector>
    using namespace std;
    typedef long long ll;
    const int inf = 1e9;
    const int mod = 1000000007;
    const int mx = 5e5+10; //check the limits, dummy
    typedef pair<int, int> pa;
    const double PI = acos(-1);
    ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
    #define swa(a,b) a^=b^=a^=b
    #define re(i,a,b) for(int i=(a),_=(b);i<_;i++)
    #define rb(i,a,b) for(int i=(a),_=(b);i>=_;i--)
    #define clr(a) memset(a, -1, sizeof(a))
    #define lowbit(x) ((x)&(x-1))
    #define mkp make_pai
    void sc(int& x) { scanf("%d", &x); }void sc(int64_t& x) { scanf("%lld", &x); }void sc(double& x) { scanf("%lf", &x); }void sc(char& x) { scanf(" %c", &x); }void sc(char* x) { scanf("%s", x); }
    int n, m, k,ans=mx,t,p,x;
    int a[mx], sum[mx],pos[mx],room[mx];
    void solve() {
        cin >> n;
        vector<int>a(n), b(n);
        re(i, 0, n)cin >> a[i];
        re(i, 0, n)cin >> b[i];
        vector<int>fuck(2, 0);
        re(i, 0, n) {
            if (a[i] > b[i] && !fuck[0]) {
                puts("NO");
                return;
            }
            else if (a[i] < b[i] && !fuck[1]) {
                puts("NO");
                return;
            }
            if (a[i] == -1)fuck[0] = 1;
            if (a[i] == 1)fuck[1] = 1;
        }
        puts("YES");
    }
    int main()
    {
        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);    
        cin >> t;
        while (t--)
        {
            solve();
        }
        return 0;
    }
  • 相关阅读:
    为什么机器学习中常常假设数据是独立同分布的?
    深度学习常见的问题
    隐马尔科夫模型(HMM)与词性标注问题
    机器学习常见问题
    特征向量、特征值以及降维方法(PCA、SVD、LDA)
    anaconda安装tensorflow后pip安装jieba出错的问题
    神经网络与BP神经网络
    tensorflow模块安装
    requests爬取百度音乐
    scrapy爬虫,爬取图片
  • 原文地址:https://www.cnblogs.com/xxxsans/p/12765201.html
Copyright © 2011-2022 走看看