洛谷 P2906 [USACO08OPEN]牛的街区Cow Neighborhoods | Set+并查集
题目:
https://www.luogu.org/problemnew/show/P2906
题解:
垃圾水题
#include<cstdio> #include<algorithm> #include<set> #define N 100005 typedef long long ll; using namespace std; struct node {ll x,y,id;bool operator < (const node &a)const {return y<a.y || (y==a.y && id<a.id);} }p[N]; multiset <node> s; multiset <node> :: iterator it; ll n,c,q[N],l,r=-1,fa[N],sz[N],ans,mx; bool cmp(node a,node b) {return a.x<b.x || (a.x==b.x && a.y<b.y);} ll find(ll x) {return fa[x]=fa[x]==x?x:find(fa[x]);} void merge(ll i,ll j) {ll x=find(i),y=find(j);if (x==y) return;if (sz[x]>sz[y]) swap(x,y);fa[x]=y,sz[y]+=sz[x]; } int main() {scanf("%lld%lld",&n,&c);for (ll i=1,x,y;i<=n;i++)scanf("%lld%lld",&x,&y),p[i].x=x+y,p[i].y=x-y,p[i].id=fa[i]=i,sz[i]=1;sort(p+1,p+1+n,cmp);for (ll i=1;i<=n;i++){q[++r]=i;while (l<r && p[q[r]].x-p[q[l]].x>c) s.erase(p[q[l]]),l++;it=s.insert(p[i]);if (it!=s.begin())if ((p[i].y-(*(--it)).y<=c)) merge(p[i].id,((*it).id)),it++;else it++;if (++it!=s.end() && (*(it)).y-p[i].y<=c )merge(p[i].id,(*it).id); }for (ll i=1;i<=n;i++) if (find(i)==i) ans++,mx=max(mx,sz[i]);printf("%lld %lld\n",ans,mx);return 0; }
转载于:https://www.cnblogs.com/mrsheep/p/8399866.html
洛谷 P2906 [USACO08OPEN]牛的街区Cow Neighborhoods | Set+并查集相关推荐
- 题解 洛谷 P3069 [USACO13JAN]牛的阵容Cow Lineup
洛谷P3069[USACO13JAN]牛的阵容CowLineup\color{#00F}{洛谷\ P3069\ [USACO13JAN]牛的阵容Cow Lineup}洛谷 P3069 [USACO13 ...
- 洛谷 3029 [USACO11NOV]牛的阵容Cow Lineup
https://www.luogu.org/problem/show?pid=3029 题目描述 Farmer John has hired a professional photographer t ...
- 洛谷P7518:宝石(倍增、可撤销并查集)
解析 算法一 定义 upx,kup_{x,k}upx,k 为节点 xxx 从自己的颜色所在位置在返祖链上往后跳 2k2^k2k 个颜色到达的节点. 可以像倍增一样的求解. 这样对于一次询问 (s,t ...
- 洛谷P2498 [SDOI2012]拯救小云公主 【二分 + 并查集】
题目 英雄又即将踏上拯救公主的道路-- 这次的拯救目标是--爱和正义的小云公主. 英雄来到boss的洞穴门口,他一下子就懵了,因为面前不只是一只boss,而是上千只boss.当英雄意识到自己还是等级1 ...
- 洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game
洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game 题目描述 Bessie is playing a number game against Farmer John, ...
- 洛谷P2879 [USACO07JAN]区间统计Tallest Cow
洛谷P2879 [USACO07JAN]区间统计Tallest Cow 题目描述 给出牛的可能最高身高,然后输入m组数据 a b,代表a,b可以相望,最后求所有牛的可能最高身高输出 输入输出格式 输入 ...
- 洛谷 P3014 [USACO11FEB]牛线Cow Line
P3014 [USACO11FEB]牛线Cow Line 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 The N (1 <= N <= 20) ...
- 洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver
P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题目描述 The cows are out exercising their hooves again! There are N ...
- 洛谷P2863 [USACO06JAN]牛的舞会The Cow Prom
稍微学习一下强连通分量. https://www.cnblogs.com/stxy-ferryman/p/7779347.html 我觉得他讲得很好. 1 #include <cstdio> ...
- 洛谷P2905 [USACO08OPEN]农场危机Crisis on the Farm
P2905 [USACO08OPEN]农场危机Crisis on the Farm 题目描述 约翰和他的奶牛组建了一只乐队"后街奶牛",现在他们正在牧场里排练.奶牛们分成一堆 一堆 ...
最新文章
- 关于不能远程连接Linux中Mysql数据库的问题
- fir.im Weekly - 做一款 App 需要考虑什么
- 【pyqt5】 读取numpy arrray 显示图片
- 系统错误_Win10系统提示0x80004005错误的解决方法
- 持续集成之 Spring Boot 实战篇
- python程序员怎么建议_资深程序员对Python新手的八个建议,超级实用!
- 通过数据评估渠道用户质量的方法
- 刚刚!腾讯宣布扩招8000人,算法岗成最大亮点!
- 魅族手机android调试模式吗,怎么开启魅族Pro5 USB调试模式 魅族Pro5 USB调试模式开启方法...
- 笔记本电脑触摸板的使用
- ES部分查询方法,elasticsearch查询方法
- BZOJ 1778: [Usaco2010 Hol]Dotp 驱逐猪猡
- 动态规划之01背包问题讲解
- 2022-2027年中国医用防护服行业市场深度分析及投资战略规划报告
- 设计模式之七大原则——里氏替换原则(LSP)(三)
- 微信小程序 首行缩进无效
- 蚂蚁金服组件 ReferenceError: primordials is not defined
- python独立网站教程_python从零到独立建设网站系列教程之基础知识篇(二)
- 华为手机如何进行ADB调试
- C#中读取流媒体视频文件转H.264具体实现方法