0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 12:18:50 +00:00

P2698 [USACO12MAR]Flowerpot S

https://www.luogu.com.cn/record/84127155
This commit is contained in:
Baoshuo Ren 2022-08-17 14:01:23 +08:00
parent 51efd8f0d0
commit b363548d85
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
21 changed files with 120 additions and 0 deletions

60
Luogu/P2698/P2698.cpp Normal file
View File

@ -0,0 +1,60 @@
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <set>
#include <utility>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int n, d, ans = std::numeric_limits<int>::max();
std::pair<int, int> points[N];
std::set<int> set;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> d;
for (int i = 1; i <= n; i++) {
cin >> points[i].first >> points[i].second;
}
std::sort(points + 1, points + 1 + n, [](auto a, auto b) -> bool {
return a.second < b.second;
});
int lst = 1;
for (int i = 1; i <= n; i++) {
int pos = std::upper_bound(points + 1, points + 1 + n, std::make_pair(0, points[i].second - d), [](auto a, auto b) -> bool {
return a.second < b.second;
})
- points;
for (int j = lst; j < pos; j++) {
set.insert(points[j].first);
}
lst = pos;
auto it1 = set.lower_bound(points[i].first),
it2 = set.upper_bound(points[i].first);
if (it1 != set.begin()) {
ans = std::min(ans, std::abs(points[i].first - *--it1));
}
if (it2 != set.end()) {
ans = std::min(ans, std::abs(points[i].first - *it2));
}
}
cout << (ans == std::numeric_limits<int>::max() ? -1 : ans) << endl;
return 0;
}

BIN
Luogu/P2698/data/P2698_1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2698/data/P2698_9.out (Stored with Git LFS) Normal file

Binary file not shown.