zoukankan      html  css  js  c++  java
  • Array transformation (change)

    Description


    There are two integer arrays (A) and (B) of length (n). The value of the array (A) will only be (1, 0) or (-1).
    You can perform the following operations multiple times:
    1. Choose any ordered pair ( ext{(i,j)}) such that (1le i lt j le n). You can select the same ordered pair ( ext{(i,j)}) multiple times.
    2. Add (A[i]) to (A[j]), that is, the (j) element of the array (A) is equal to (A[i]+A[j]).
    For example, if the given array (A) is ([1,−1,0]), you can transform it into ([1,−1,−1]), ([1,0,0]) and ([1,−1,1])in one operation.
    The problem now is, given the arrays (A) and (B), determine whether a certain number ((0) or more) of these operations can be applied to the array (A) to make it equal to the array (B).

    Format


    Input

    Contains multiple sets of test data. An integer (T) in the first line indicates the number of test data sets. Each set of test data contains:
    The first line contains an integer (n), which represents the length of the array.
    The second line contains (n) integers (A[1], A[2], cdots, A[n](-1le A[i] le 1)) describe the (A) array.
    The third line contains (n) integers (B[1], B[2], cdots, B[n](-10^9 le B[i] le 10^9)) description array (B) .

    Output

    For each set of data output one line, if the arrays (A) and (B) can be made equal by performing the operations in the title description, then output YES, otherwise output NO.

    Sample


    Input

    2
    3
    1 -1 0
    1 1 -2
    3
    0 1 1
    0 2 2
    

    Output

    YES
    NO
    

    Sample Explanation

    In the first set of data, select the ordinal pair ( ext{(2,3)}) to execute (2) times, and select the ordinal number pair ( ext{(1,2)}) to execute (2) times, then the array (A) becomes the same as the array (B).

    Hint


    Data for (100\%): (1 le T le 10000, 1 le n le 10^5), make sure that the sum of (n) in multiple sets of data for each test point does not exceed (10^5).

    Sample Code


    Code is not available!
    
  • 相关阅读:
    MySQL存储引擎MyISAM和InnoDB有哪些区别?
    python发起post请求获取json数据使用requests方法
    和 Python 2.x 说再见!项目移到python3
    php memcache 缓存与memcached 客户端的详细步骤
    Ubuntu16.04安装Nginx+PHP5.6+MySQL5.6
    element-ui select 下拉框 实现分页 通过css样式
    技术_pm发展历程
    前端_git用法
    前端_javascript本地实现分页(摘录)
    生活_人生感悟
  • 原文地址:https://www.cnblogs.com/jiupinzhimaguan/p/13817353.html
Copyright © 2011-2022 走看看