【离散化】【DFS】Gym - 101617H - Security Badges
题意:给你一张有向图,每条边有个限制范围,只有权值在限制范围内的人能走这条边,问你权值不超过K的人中,有多少人能从S到T。
K很大,因此我们只处理边的范围的上下界这O(m)个权值能否到达,以防万一,还处理了这些权值+1、-1的可达性。然后去重。离散化出来的这些区间中,两个端点都可达的话,其内部的点也必然可达。当然端点本身也是可达的。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
set<int>S;
bool cant[5005],vis[1005];
int first[1005],nex[5005],v[5005],w1[5005],w2[5005],e;
void AddEdge(int U,int V,int W1,int W2){
v[++e]=V;
w1[e]=W1;
w2[e]=W2;
nex[e]=first[U];
first[U]=e;
}
int n,m,K,Sta,End,b[30005],q;
bool c[30005];
void dfs(int U){
vis[U]=1;
for(int i=first[U];i;i=nex[i]){
if(!cant[i] && !vis[v[i]]){
dfs(v[i]);
}
}
}
void Insert(int x){
if(S.find(x)==S.end()){
b[++q]=x;
S.insert(x);
}
}
int main(){
int x,y,z1,z2;
//freopen("h.in","r",stdin);
scanf("%d%d%d%d%d",&n,&m,&K,&Sta,&End);
for(int i=1;i<=m;++i){
scanf("%d%d%d%d",&x,&y,&z1,&z2);
AddEdge(x,y,z1,z2);
if(z1!=1){
Insert(z1-1);
}
Insert(z1);
if(z1!=K){
Insert(z1+1);
} if(z2!=1){
Insert(z2-1);
}
Insert(z2);
if(z1!=K){
Insert(z2+1);
}
}
sort(b+1,b+q+1);
/*for(int i=1;i<=q;++i){
printf("%d ",b[i]);
}
puts("");*/
int ans=0;
for(int i=1;i<=q;++i){
memset(cant,0,sizeof(cant));
for(int j=1;j<=e;++j){
if(b[i]<w1[j] || b[i]>w2[j]){
cant[j]=1;
}
}
memset(vis,0,sizeof(vis));
dfs(Sta);
if(vis[End]){
c[i]=1;
++ans;
}
}
/*for(int i=1;i<=q;++i){
if(c[i]){
printf("%d ",b[i]);
}
}
puts("");*/
for(int i=1;i<q;++i){
if(c[i] && c[i+1]){
ans+=(b[i+1]-b[i]-1);
}
}
printf("%d\n",ans);
return 0;
}
【离散化】【DFS】Gym - 101617H - Security Badges的更多相关文章
- hdu4605 树状数组+离散化+dfs
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- Aizu 0531 "Paint Color" (坐标离散化+DFS or BFS)
传送门 题目描述: 为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌. 三合板上不需要涂色的部分预先贴好了护板. 被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编写一个程序计 ...
- dfs | Security Badges
Description You are in charge of the security for a large building, with n rooms and m doors between ...
- 2016 长春东北赛---Coconuts(离散化+DFS)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5925 Problem Description TanBig, a friend of Mr. Frog ...
- UVALive 6663 Count the Regions --离散化+DFS染色
题意:给你n(n<=50)个矩形(左上角坐标和右下角坐标),问这些矩形总共将平面分成多少个部分.坐标值可能有1e9. 分析:看到n和坐标的范围,容易想到离散化,当时就没想到离散化以后怎么判断区域 ...
- hdu 4358 Boring counting 离散化+dfs序+莫队算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4358 题意:以1为根节点含有N(N <= 1e5)个结点的树,每个节点有一个权值(weight ...
- (好题)树状数组+离散化+DFS序+离线/莫队 HDOJ 4358 Boring counting
题目传送门 题意:给你一棵树,树上的每个节点都有树值,给m个查询,问以每个点u为根的子树下有多少种权值恰好出现k次. 分析:首先要对权值离散化,然后要将树形转换为线形,配上图:.然后按照右端点从小到大 ...
- DFS Gym 100553J Jokewithpermutation
题目传送门 /* 题意:将字符串分割成一个全排列 DFS:搜索主要在一位数和两位数的处理,用d1, d2记录个数,在不饱和的情况下,两种都试一下 DFS还是写不来,难道是在家里懒? */ #inclu ...
- UvaLive 6663 Count the Regions 离散化+DFS
链接:http://vjudge.net/problem/viewProblem.action?id=49408 题意:在平面内给出若干个矩形,求出它们能将整个平面分成多少份. 思路:刚開始一眼看到认 ...
随机推荐
- 数据库-Core Data
技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong 数据库-Core Data 技术博客htt ...
- laravel 模糊查询
模糊查询: Model::where('field_name','like','%'.$keywords.'%')->get() 转载:http://wenda.golaravel.com/qu ...
- 项目记录 -- config2html 理解
html 代码: <table width=1280 border=0 cellspacing=1 cellpadding=1> <tr id=tblhdr> <td&g ...
- 【swupdate文档 三】SWUpdate: 嵌入式系统的软件升级
SWUpdate: 嵌入式系统的软件升级 概述 本项目被认为有助于从存储媒体或网络更新嵌入式系统.但是,它应该主要作为一个框架来考虑,在这个框架中可以方便地向应用程序添加更多的协议或安装程序(在SWU ...
- MySQL源码分析(一)
近段时间简单看了下Mysql源码相关内容,主要从一个select查询出发,查看了一下整个代码结构.分析总结如下: https://mubu.com/doc/explore/13965
- 64_q1
QMsgBox-0-9.20130830git94677dc.fc26.i686.rpm 13-Feb-2017 23:40 40674 QMsgBox-0-9.20130830git94677dc. ...
- iTextSharp之pdfRead(两个文件文本内容的比较,指定页数的pdf截取,水印的添加)
using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.pdf.parser; using System; us ...
- 服务号使用微信网页授权(H5应用等)
获取授权准备 AppId 服务号已经认证且获取到响应接口权限 设置网页授权域名 公众号设置 - 功能设置 - 网页授权域名.注意事项: 回调页面域名或路径需使用字母.数字及"-"的 ...
- oracle只要第一条数据SQL
select * from ( select * from COMMON_BIZREL_WF where sponsor is not null order by serialid ) where r ...
- TreeSet基本用法
TreeSet的基础方法: public class TreeSetTest { public static void main(String[] args) { TreeSet nums = new ...