#include <stdio.h> #include <algorithm> #include <stdlib.h> struct MyStruct { int l, r; }a[105]; bool compare(MyStruct a, MyStruct b) { return a.l < b.l; } bool good(int min, int n) { for (int i = 0; i <= min; i++) { for (int j = 1; j < 50001; j++) { int count = 0; for (int li = 1; li <= n && i + j * li < 50001; li++) { int l1 = i + j * (li - 1); int r1 = i + j * li; int c = 0; for (int k = 0; k < n; k++) { if (l1 <= a[k].l && r1 >= a[k].r) c++; } if (c == 1) { count++; } else { break; } } if (count == n) { puts("YES"); return true; } } } return false; } int main() { int t, n; scanf("%d", &t); while (t--) { scanf("%d", &n); int min = 50005, max; for (int i = 0; i < n; i++) { scanf("%d%d", &a[i].l, &a[i].r); if (a[i].l < min) min = a[i].l; } bool con = true; for (int i = 0; i < n && con; i++) for (int j = 0; j < n; j++) { if (i != j) { if (a[i].r <= a[j].l || a[j].r <= a[i].l) {} else { con = false; break; } } } if (con == false) { puts("NO"); continue; } std::sort(a, a + n, compare); if (!good(min, n)) { puts("NO"); } } } |
Double click to view unformatted code.