mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 13:18:46 +00:00
1604. [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居
https://hydro.ac/d/bzoj/record/6322ef45bdf9bc31d160a341
This commit is contained in:
parent
1a5233b4cb
commit
0317384c93
62
BZOJ/1604/1604.cpp
Normal file
62
BZOJ/1604/1604.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e5 + 5;
|
||||
|
||||
int n, c, fa[N], cnt[N], ans, max;
|
||||
std::pair<int, int> points[N];
|
||||
std::set<std::pair<int, int>> set;
|
||||
|
||||
int find(int x) {
|
||||
return fa[x] == x ? x : fa[x] = find(fa[x]);
|
||||
}
|
||||
|
||||
inline void merge(int x, int y) {
|
||||
fa[find(x)] = find(y);
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> c;
|
||||
|
||||
for (int i = 1, x, y; i <= n; i++) {
|
||||
cin >> x >> y;
|
||||
|
||||
points[i] = std::make_pair(x + y, x - y);
|
||||
fa[i] = i;
|
||||
}
|
||||
|
||||
std::sort(points + 1, points + 1 + n);
|
||||
|
||||
set.insert(std::make_pair(points[1].second, 1));
|
||||
for (int i = 2, l = 1; i <= n; i++) {
|
||||
while (points[i].first - points[l].first > c) {
|
||||
set.erase(std::make_pair(points[l].second, l));
|
||||
l++;
|
||||
}
|
||||
|
||||
auto it = set.lower_bound(std::make_pair(points[i].second, 0));
|
||||
|
||||
if (it != set.end() && it->first - points[i].second <= c) merge(i, it->second);
|
||||
if (it != set.begin() && points[i].second - (--it)->first <= c) merge(i, it->second);
|
||||
|
||||
set.insert(std::make_pair(points[i].second, i));
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (find(i) == i) ans++;
|
||||
|
||||
max = std::max(max, ++cnt[find(i)]);
|
||||
}
|
||||
|
||||
cout << ans << ' ' << max << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
BZOJ/1604/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/11.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/11.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/12.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/12.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/13.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/13.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/14.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/14.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/15.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/15.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/5.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/5.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/6.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/6.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/7.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/7.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/8.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/8.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/9.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1604/data/9.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1604/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user