[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 ...
随机推荐
- 基于Apache CXF的Web Service服务端/客户端
转自:https://www.aliyun.com/zixun/wenji/1263190.html CXF服务端: package com.sean.server; import javax.jws ...
- 在阿里云的iis上安装php扩展
具体参照http://jingyan.baidu.com/article/11c17a2c5ce349f447e39d6d.html
- Python笔记(七)
# -*-coding:utf-8-*- # Python 文件I/O # 打印到屏幕 #print 1234567 # 读取屏幕输入 #input_str=raw_input("Pleas ...
- jQuery在多个div中,删除指定项
之前工作中有一个需求,就是在一堆图片列表中,点击具体的图片,并从界面移除:点击具体的图片,下载:这是一个思路 <style type="text/css" media=&qu ...
- RecyclerView的刷新和加载更多
1.RecyclerView :出现也不知道多久了,没怎么使用过,上次写的笔记乱七八糟的,再次仔细的整理下. 使用需加入依赖 compile 'com.android.support:recyc ...
- POJ 1458 Common Subsequence 【最长公共子序列】
解题思路:先注意到序列和串的区别,序列不需要连续,而串是需要连续的,先由样例abcfbc abfcab画一个表格分析,用dp[i][j]储存当比较到s1[i],s2[j]时最长公共子序 ...
- 3DSMAX制作逼真的欧式沙发建模教程
这篇教程是朋友们介绍利用3DSMAX制作逼真的欧式沙发建模,教程制作出来的效果真心很不错,通过这篇教程,大家可以学习沙发建模的制作方法和思路,推荐过来,一起来学习吧! 3DSMAX软件下载:http: ...
- zabbix部署监控端(server)以及页面优化
实验环境准备 172.20.10.2 server.zabbix.com 172.20.10.3 agent.zabbix.com 172.20.10.8 windows10 Server 端 [ro ...
- Java web课程学习之会话(Session)
Session会话 l web应用中的会话是指一个客户端浏览器与web服务器之间连续发生一系列请求和响应过程 l web应用的会话状态是指web服务器与浏览器在会话过程中产生的状态信息,借助会话状 ...
- HDU 5776 sum( 鸽巢定理简单题 )
链接:传送门 题意:给一个长为 n 的串,问是否有子串的和是 m 的倍数. 思路:典型鸽巢定理的应用,但是这里 n,m 的大小关系是不确定的,如果 n >= m 根据定理可以很简单的判定是一定有 ...