5177. 【NOIP2017提高组模拟6.28】TRAVEL (Standard IO)
Description
Input
Output
Solution
有大佬说:可以用LCT做。(会吗?不会)
对于蒟蒻的我,只好用水法(3s,不虚)。
首先选出的泡泡怪一定是连续的一段 L,
R 然后 L 一定属于虫洞左边界中的某一个 R 也同样是这样的 这样就可以枚举 L 和 R,
O(N)判断是否可行,可用并查集, 总复杂度 O(NM^2)。
代码
1 type 2 arr=record 3 x,y,l,r:longint; 4 end; 5 var 6 n,m,tk,ans,ll:longint; 7 a:array [0..3001] of arr; 8 fa:array [0..1001] of longint; 9 function max(o,p:longint):longint; 10 begin 11 if o>p then exit(o); 12 exit(p); 13 end; 14 15 procedure init; 16 var 17 i:longint; 18 begin 19 readln(n,m); 20 tk:=0; 21 for i:=1 to m do 22 begin 23 readln(a[i].x,a[i].y,a[i].l,a[i].r); 24 tk:=max(tk,a[i].r); 25 end; 26 end; 27 28 procedure qsort(l,r:longint); 29 var 30 i,j,mid:longint; 31 t:arr; 32 begin 33 if l>r then exit; 34 i:=l; j:=r; 35 mid:=a[(l+r) div 2].r; 36 repeat 37 while a[i].r<mid do inc(i); 38 while a[j].r>mid do dec(j); 39 if i<=j then 40 begin 41 t:=a[i]; a[i]:=a[j]; a[j]:=t; 42 inc(i); dec(j); 43 end; 44 until i>j; 45 qsort(i,r); 46 qsort(l,j); 47 end; 48 49 function get(x:longint):longint; 50 begin 51 if (fa[x]=0) or (fa[x]=x) then exit(x); 52 fa[x]:=get(fa[x]); 53 exit(fa[x]); 54 end; 55 56 function fd(l,r:longint):boolean; 57 var 58 i,x,y:longint; 59 begin 60 fillchar(fa,sizeof(fa),0); 61 for i:=1 to m do 62 if (a[i].l<=l) and (a[i].r>=r) then 63 begin 64 x:=get(a[i].x); y:=get(a[i].y); 65 fa[x]:=y; 66 end; 67 if get(1)=get(n) then exit(true); 68 exit(false); 69 end; 70 71 procedure main; 72 var 73 i,r,l,mid,t:longint; 74 begin 75 ans:=0; 76 for i:=1 to m do 77 begin 78 l:=1; r:=tk; 79 while l+1<r do 80 begin 81 mid:=(l+r) div 2; 82 if fd(a[i].l,mid) then l:=mid 83 else r:=mid; 84 end; 85 if not fd(a[i].l,r) then r:=l; 86 t:=r-a[i].l+1; 87 if (t>ans) or (t=ans) and (a[i].l<ll) then 88 begin 89 ans:=t; ll:=a[i].l; 90 end; 91 end; 92 end; 93 94 procedure print; 95 var 96 i,rr:longint; 97 begin 98 writeln(ans); 99 rr:=ans+ll-1; 100 for i:=ll to rr do 101 write(i,' '); 102 end; 103 104 begin 105 init; 106 qsort(1,m); 107 main; 108 print; 109 end.
转载于:https://www.cnblogs.com/zyx-crying/p/9464330.html
5177. 【NOIP2017提高组模拟6.28】TRAVEL (Standard IO)相关推荐
- JZOJ 5177. 【NOIP2017提高组模拟6.28】TRAVEL
Description Input Output Sample Input 4 4 1 2 1 10 2 4 3 5 1 3 1 5 2 4 2 7 Sample Output 6 2 3 4 5 6 ...
- 5178. 【NOIP2017提高组模拟6.28】So many prefix? (Standard IO)
Description PCY学生物学累了.突然看到地上有一本笔记本. 上面写着"isdashagaydashisorosdashnot..."之类的字眼,独具慧眼的他发现这些字符 ...
- NOIP2017提高组模拟赛4 (总结)
NOIP2017提高组模拟赛4 (总结) 第一题 约数 设K是一个正整数,设X是K的约数,且X不等于1也不等于K. 加了X后,K的值就变大了,你可以重复上面的步骤.例如K= 4,我们可以用上面的规则产 ...
- 计蒜客NOIP2017提高组模拟赛(四)day1
T1:小X的质数 小 X 是一位热爱数学的男孩子,在茫茫的数字中,他对质数更有一种独特的情感.小 X 认为,质数是一切自然数起源的地方. 在小 X 的认知里,质数是除了本身和 1 以外,没有其他因数的 ...
- JZOJ 5182. 【NOIP2017提高组模拟6.29】码灵鼠
Description 码零鼠是一只很喜欢mx数学的神犇,上面那个不是ta本人的样子.这天,ta在研究一个神奇的数列,这个数列是这样的: a0 = 1 an = ai + aj (n>=1, i ...
- JZOJ 4932. 【NOIP2017提高组模拟12.24】B
Description 现在你有 NN 个数,分别为 A1,A2,-,ANA1,A2,-,AN ,现在有M组询问需要你回答.每个询问将会给你一个L和R(L<=R)(L,保证 MaxAi−MinA ...
- 计蒜客NOIP2017提高组模拟赛(三)day2-小区划分
传送门 dp,注意边界 1 #include<cstdio> 2 #include<cstdlib> 3 #include<algorithm> 4 #includ ...
- JZOJ 5197. 【NOIP2017提高组模拟7.3】C
Description Input Output Sample Input 3 Sample Output 1 Data Constraint Solution 这题我的方法是打表找规律,可以发现答案 ...
- JZOJ 5195. 【NOIP2017提高组模拟7.3】A
Description Input Output Sample Input 7 3 Sample Output 4 Data Constraint Solution 这是一道经典的DP问题了,也可以把 ...
最新文章
- 深入理解 JavaScript 原型
- LeetCode 375. Guess Number Higher or Lower II
- VB.NET 在项目中添加App.config的配置
- php5.3+for+linux,Centos 安装 nginx + php5.3
- 知识图谱论文阅读(十八)【KDD2019】AKUPM: Attention-Enhanced Knowledge-Aware User Preference Model for Recommend
- 妈妈再也不用担心别人问我是否真正用过redis了
- Latex初学者入门
- 根据某一字段值去重查找出所有字段的数据
- webpack环境的配置
- 电商时代,谁是手持数据采集巴枪的终结者【转】
- wifi模块和51单片机相连的问题
- ASP.NET学习笔记(二)——一般处理程序之图片上传
- zheng项目新建一个module学习学习
- Openbravo怎么给工具栏添加一个按钮
- 在安装SVN时出现Custom action GenerateSSLKey failed: Command terminated with non-zero exit code
- JavaScript 各种参数 详解(十二)
- vscode国内下载
- SHOI2002 百事世界杯之旅
- SQL Server数据库开发(3.SQL高级查询)
- python画旺仔代码_Python基础3
热门文章
- 各种光源(灯)的光谱
- 施密特触发器(Schmitt Trigger)?
- ubuntu14.04的键盘失灵解决方案
- Python矩阵的用法(使用numpy)
- 华为2017年财报,为何6036亿销售收入,净利润才479亿?
- 商务英语老师给的6个建议
- [转] 常见WinCE启动失败原因分析
- java教程菜鸟教程组合模式,组合实体模式
- java 验证码_Java - 验证码 - 由Kaptcha组件实现
- mysql5.7和8.0的区别_解答阿迪达斯Adidas ultra boost4.0与正品区别!如何选择?