欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

codeforces A. Nastya and Rice

程序员文章站 2022-06-08 16:26:18
...

codeforces A. Nastya and Rice

题目

题意:

对于每一个样例,是否满足n({abxa+b})=({cdyc+d})\exists n*(\{a-b\leq x\leq a+b\}) = (\{c-d\leq y\leq c+d\})

思路:

我们把n({abxa+b})n*(\{a-b\leq x\leq a+b\})算出来,然后和yy进行对比,看看是否相加,不相交的情况是nmax(x)<min(y)n * max(x) < min(y)nmin(x)>max(y)n*min(x) > max(y),排除这两种就是其他的都是YesYes了

#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');
}
int main() {
    int t;
    read(t);
    while (t--) {
        int n, a, b, c, d;
        read(n), read(a), read(b), read(c), read(d);
        int x = (a - b) * n;
        int y = (a + b) * n;
        int xx = (c - d);
        int yy = c + d;
        if (x > yy) {
            printf("No\n");
            continue;
        } else if (xx > y) {
            printf("No\n");
            continue;
        }
        printf("Yes\n");
    }
    return 0;
}

相关标签: codeforces