codeforces B. Kind Anton

在这里插入图片描述

题目

题意:

给你一个序列 a a 和一个序列 b b 你可以选择两个下标 i , j i,j ,然后 a j + = a i a_j+=a_i ,问最后的序列会不会等于 b b

思路:

因为 i < j i<j ,所以假如 a i a_i 出现过 1 1 的情况的时候,那么只要 a j < = b j a_j<=b_j 的话,都可以通过无限次累加达到一样的, 1 -1 的时候同理。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return ;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1:1;
    ret = (c == '-') ? 0:(c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return ;
}
inline void out(int x) {
    if (x > 9) out(x / 10);
    putchar(x % 10 + '0');
}
const int maxn = 100010;
int a[maxn], b[maxn];
int main() {
    int t, n;
    read(t);
    while (t--) {
        read(n);
        for (int i = 0; i < n; i++) read(a[i]);
        for (int i = 0; i < n; i++) read(b[i]);
        bool cnt_1 = false, cnt1 = false, flag = false;
        for (int i = 0; i < n; i++) {
            if (a[i] < b[i] && !cnt1) {
                flag = true;
                break;
            } else if (a[i] > b[i] && !cnt_1) {
                flag = true;
                break;
            }
            if (a[i] == -1) cnt_1 = true;
            else if (a[i] == 1) cnt1 = true;
            if (cnt1 && cnt_1) break;
        }
        if (flag) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

发布了463 篇原创文章 · 获赞 27 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/weixin_45031646/article/details/105417544