[jzoj 5177] [NOIP2017提高组模拟6.28] TRAVEL 解题报告 (二分)
题目链接:
https://jzoj.net/senior/#main/show/5177
题目:
题解:
首先选出的泡泡怪一定是连续的一段 L,R
然后 L 一定属于虫洞左边界中的某一个 R 也同样是这样的
这样就可以枚举 L 和 R,$O(N)$判断是否可行(显然不可能重复经过某个点),总复杂度 $O(NM^2)$
我们看到 R<=1e6 选择二分 R 而不是枚举,这样就可以了
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std; const int N=1e3+;
const int M=3e3+;
const int inf=1e6;
int n,m,tot;
int head[N],L[M],vis[N];
struct EDGE{
int to,nxt,l,r;
}edge[M<<];
inline int read(){
char ch=getchar();int s=,f=;
while (ch<''||ch>'') {if (ch=='-') f=-;ch=getchar();}
while (ch>=''&&ch<='') {s=(s<<)+(s<<)+ch-'';ch=getchar();}
return s*f;
}
void link(int u,int v,int l,int r){
edge[++tot]=(EDGE){v,head[u],l,r};
head[u]=tot;
}
bool dfs(int x,int l,int r)
{
if (x==n) return ;
if (vis[x]) return ;
vis[x]=;
for (int i=head[x];i;i=edge[i].nxt)
{
if (edge[i].l<=l&&edge[i].r>=r)
{
if (dfs(edge[i].to,l,r)) return ;
}
}
return ;
}
bool check(int l,int r)
{
memset(vis,,sizeof(vis));
if (dfs(,l,r)) return ;
return ;
}
int main()
{
n=read();m=read();
for (int i=,u,v,l,r;i<=m;i++){
u=read();v=read();l=read();r=read();
link(u,v,l,r);link(v,u,l,r);
L[i]=l;
}
sort(L+,L++m);
int ans=,al,ar;
for (int i=m;i;i--){
int l=L[i],r=inf;
while (l+<r)
{
int mid=l+r>>;
if (check(L[i],mid))
{
if (mid-L[i]+>=ans)
{
ans=mid-L[i]+;
al=L[i];ar=mid;
}
l=mid;
}
else r=mid;
}
}
printf("%d\n",ans);
for (int i=al;i<=ar;i++) printf("%d ",i);
return ;
}
[jzoj 5177] [NOIP2017提高组模拟6.28] TRAVEL 解题报告 (二分)的更多相关文章
- [jzoj 5178] [NOIP2017提高组模拟6.28] So many prefix? 解题报告(KMP+DP)
题目链接: https://jzoj.net/senior/#main/show/5178 题目: 题解: 我们定义$f[pos]$表示以位置pos为后缀的字符串对答案的贡献,答案就是$\sum_{i ...
- [JZOJ 5852] [NOIP2018提高组模拟9.6] 相交 解题报告 (倍增+LCA)
题目链接: http://172.16.0.132/senior/#main/show/5852 题目: 题目大意: 多组询问,每次询问树上两条链是否相交 题解: 两条链相交并且仅当某一条链的两个端点 ...
- [JZOJ5178]【NOIP2017提高组模拟6.28】So many prefix?
Description
- nowcoder(牛客网)提高组模拟赛第一场 解题报告
T1 中位数(二分) 这个题是一个二分(听说是上周atcoder beginner contest的D题???) 我们可以开一个数组b存a,sort然后二分b进行check(从后往前直接遍历check ...
- JZOJ 5184. 【NOIP2017提高组模拟6.29】Gift
5184. [NOIP2017提高组模拟6.29]Gift (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Detailed ...
- JZOJ 5196. 【NOIP2017提高组模拟7.3】B
5196. [NOIP2017提高组模拟7.3]B Time Limits: 1000 ms Memory Limits: 262144 KB Detailed Limits Goto Pro ...
- JZOJ 5197. 【NOIP2017提高组模拟7.3】C
5197. [NOIP2017提高组模拟7.3]C Time Limits: 1000 ms Memory Limits: 262144 KB Detailed Limits Goto Pro ...
- JZOJ 5195. 【NOIP2017提高组模拟7.3】A
5195. [NOIP2017提高组模拟7.3]A Time Limits: 1000 ms Memory Limits: 262144 KB Detailed Limits Goto Pro ...
- JZOJ 5185. 【NOIP2017提高组模拟6.30】tty's sequence
5185. [NOIP2017提高组模拟6.30]tty's sequence (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB ...
随机推荐
- Android获取系统时间的多种方法
Android中获取系统时间有多种方法,可分为Java中Calendar类获取,java.util.date类实现,还有android中Time实现. 现总结如下: 方法一: ? 1 2 3 4 5 ...
- 0x15 KMP
这个算法本身就不难. poj1961 #include<cstdio> #include<iostream> #include<cstring> #include& ...
- DatabaseMetaData开发实务
1.总论 在企业开发实务中,数据迁移是经常会遇到的事情,此时,需要搞清楚,源数据库与目的数据库之间表以及表内部各列之间的异同.而有些时候,我们拿到的项目文 档,未必能准确表述各个表的准确结构,即使应用 ...
- 【IOI 2011】Race
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2599 [算法] 点分治 [代码] #include<bits/stdc++.h ...
- SpringCloud微服务Docker部署
前两写了两篇,都是为SpringCloud+Docker部署做准备,在部署的时候,不同服务器,不同的Docker容器之间的通信,还好没有掉到坑里去,在公司里用了新技术,还是很开心的,小有成就感,之前一 ...
- POJ 3411 DFS
大致题意: 有n座城市和m(1<=n,m<=10)条路.现在要从城市1到城市n.有些路是要收费的,从a城市到b城市,如果之前到过c城市,那么只要付P的钱,如果没有去过就付R的钱.求的是最少 ...
- less使用方法总结
1 变量 我们常常在 CSS 中 看到同一个值重复多次,这样难易于代码维护. 理想状态,应是下面这样: const bgColor="skyblue"; $(".post ...
- 编码介绍(ANSI、GBK、GB2312、UTF-8、GB18030和 UNICODE)
转载:http://blog.jobbole.com/30526/(前面内容)和http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf ...
- SSH 项目中 用Hibernate底层 简单的封装DAO层
废话不多少了,主要是使用hibernate的查询方法,自己封装了DAO层,供service来方便使用. 首先:必须要继承的 public class CommonDao extends Hiberna ...
- CF1012B Chemical table 构造_思维_并查集
我们可以将横坐标和纵坐标看成是点.发现这些点之间是有传递性的. 题中说明,如果有矩阵中三个顶点被选,则底角的点也会被覆盖,发现这些点之间是有传递性的.那么我们最终达到的目的就是使整个图中只有 111 ...