Dima and Trap Graph ------codeforces #214 div.2
来源:互联网 发布:泛微邮箱服务器端口 编辑:程序博客网 时间:2024/04/25 12:32
http://codeforces.com/contest/366
本题就是求一条路径,使得该路径上所有区间的公共子区间最大,输出最大值。
直接枚举该区间,再用DFS去判断使用这个区间的时候能不能从1节点走到n节点。
对于区间的左端点直接暴力枚举,枚举每一个出现过的左端点,对于右端点,采用二分枚举就可以了。
#include <cstdlib>#include <iostream>#include <cmath>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define inf 2147480000int n,m;int v[10001];int next[10001];int head[10001];int r[10001];int l[10001];int o;int box[3001];int maxn;bool pig[1001];bool dfs(int a,int l1,int r1){ if(a==n) return true; if(l1>r1) return false; for(int p=head[a];p>0;p=next[p]) { if(!pig[v[p]]) { if(l[p]<=l1 && r[p]>=r1) { pig[v[p]]=1; if(dfs(v[p],l1,r1)) return true; } } } return false;}int main(int argc, char *argv[]){ cin>>n>>m; for(int i=1;i<=m;i++) { int a,b,c,d; cin>>a>>b>>c>>d; o++;v[o]=b;next[o]=head[a];head[a]=o;l[o]=c;r[o]=d; o++;v[o]=a;next[o]=head[b];head[b]=o;l[o]=c;r[o]=d; box[i]=c; maxn=max(maxn,d); } sort(box+1,box+1+m); int now=-1; int best=-1; for(int i=1;i<=m;i++) { if(now!=box[i]) { now=box[i]; int final=-1; int ll=now;int rr=maxn; while(ll<=rr) { int mid=(ll+rr)/2; memset(pig,0,sizeof(pig)); pig[1]=1; if(dfs(1,now,mid)) {final=mid;ll=mid+1;} else rr=mid-1; } if(final>=now) best=max(best,final-now+1); } } if(best!=-1) cout<<best<<endl; else cout<<"Nice work, Dima!"<<endl; return 0;}
- Dima and Trap Graph ------codeforces #214 div.2
- Codeforces Round #214 (Div. 2) D. Dima and Trap Graph (枚举+二分+搜索)
- codeforces Dima and Trap Graph
- Dima and Trap Graph CodeForces
- Dima and Trap Graph CodeForces
- CodeForces 366D Dima and Trap Graph
- cf-Round #214 (Div. 2)-D-Dima and Trap Graph-dfs+二分
- Codeforces 366D Dima and Trap Graph 【并查集】
- Codeforces 366D Dima and Trap Graph【二分+Dfs】
- Dima and Salad -----codeforces # 214 div.2
- Codeforces 366D Dima and Trap Graph (DFS剪枝水过...)
- CodeForces - 366D Dima and Trap Graph (并查集&技巧)好题
- Codeforces--366D--Dima and Trap Graph(并查集)
- Codeforces 366D Dima and Trap Graph(搜索剪枝/二分)
- codeforces 366D Dima and Trap Graph 题解(搜索+剪枝or二分+枚举)
- Codeforces Round #214 (Div. 2) C. Dima and Salad
- Codeforces Round #214 (Div. 2) C. Dima and Salad
- Codeforces Round #214 (Div. 2)——Dima and Salad
- 快速排序算法---20世纪十大算法之一
- 手工设置Windows服务依赖关系
- iOS笔记:自带TableCell中imageView和textLabel位置调整(layoutSubviews)
- MFC 处理双击事件时屏蔽掉单击事件
- code inspector
- Dima and Trap Graph ------codeforces #214 div.2
- Jacob控制word文档拷贝段落内容
- Cimage类处理图像像素(数据)的3种方式
- java核心概念
- 内存管理(SAP和ABAP内存)缓存设定以及程序memory管理等
- linux内核文件系统烧写
- [探究]事务日志截断是否会影响事务复制?
- C#开机启动
- 中百般忧愁,千般缅怀。而你,