你可以使用以下C++代码来解决这个问题:

#include <iostream>
#include <vector>

using namespace std;

bool checkPairs(vector<int>& x, vector<int>& y) {
    int n = x.size();
    bool result = false;
    
    for (int i = 0; i < n; i++) {
        bool found = false;
        for (int j = 0; j < n; j++) {
            if (y[j] > y[i] && abs(x[i]-x[j]) <= abs(y[j]-y[i])) {
                found = true;
                break;
            }
        }
        if (!found) {
            result = true;
            break;
        }
    }
    
    return result;
}

int main() {
    int n;
    cin >> n;
    
    vector<int> x(n);
    vector<int> y(n);
    
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    
    bool result = checkPairs(x, y);
    
    if (result) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

在此代码中,checkPairs函数将两个向量xy作为输入,并检查是否存在满足条件的一对(x[j], y[j])。如果存在满足条件的一对,则返回true,否则返回false

main函数中,首先输入n表示向量的长度。然后,输入nxy的值。最后,调用checkPairs函数,并根据返回值输出结果。

希望对你有帮助!

给定n个 xi 和 yi 1=i=n 求对于每个i 是否有一对xjyj符合yjyi 且 xi-xj的绝对值小于等于yj-yi使用C++

原文地址: https://www.cveoy.top/t/topic/jc8d 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录