Codeforces 320B Ping-Pong (Easy Version)
来源:互联网 发布:win7所有软件都打不开 编辑:程序博客网 时间:2024/05/01 10:09
题目链接:http://codeforces.com/contest/320/problem/B
题意:先输入n,接下来输入n行,每行输入三个数,q,a,b,若q==1,则添加一个区间(a,b)。若q==2,表示查询第a个区间能否到达第b个区间。注意: 区间a:(x,y)能到区间b(c,d)的条件是:
c < x < d || c < y < d
这个条件有些特殊,一旦从一个小区间进入一个包含它的大区间后就不能再进入它包含的任何一个小区间了。
思路:因为n数量级不大,才100。直接dfs。但需要注意,搜的时候回溯条件不需要改变,因为对每次查询的vis[i]表示是否存在一条路从a到i,若存在就不需要继续重复搜了。
#include <iostream>#include <iomanip>#include <cstdio>#include <algorithm>#include <cmath>#include <queue>#include <vector>#include <stack>#include <string>#include <cstring>#include <cassert>using namespace std;typedef long long ll;const int maxn=2222;const int INF=0x7fffffff;const int mod=1e7+7;#define LSON l,m,rt<<1#define RSON m+1,r,rt<<1|1#define ESP 1e-7struct point { int l,r;};point p[111];int n,sum;bool vis[111];bool check(int a, int b) {//判断区间a能否到区间b if(p[a].l>p[b].l && p[a].l<p[b].r) return true; else if(p[a].r>p[b].l && p[a].r<p[b].r) return true; return false;}bool dfs(int now, int ed) { if(now==ed) { return true; } for(int i=1;i<sum;i++) { if(check(now, i) && !vis[i]) { vis[i]=true; if(dfs(i, ed)) return true; } } return false;}int main() { scanf("%d", &n); sum=1; for(int cc=0;cc<n;cc++) { int order; scanf("%d", &order); if(order==1) { scanf("%d%d", &p[sum].l, &p[sum].r); sum++; } else { int a,b; scanf("%d%d", &a, &b); for(int i=1;i<sum;i++) vis[i]=false; vis[a]=true; if(dfs(a, b)) printf("YES\n"); else printf("NO\n"); } } return 0;}
0 0
- Codeforces 320B Ping-Pong (Easy Version)
- codeforces 320B Ping-Pong (Easy Version)
- Round #189 (Div.2) B. Ping-Pong (Easy Version)
- CodeForces 320BPing-Pong (Easy Version)-DFS
- CodeForces 320 B. Ping-Pong DFS BFS 弗洛伊德算法
- Ping pong
- Ping pong
- Ping pong
- Ping pong
- Ping pong
- Ping pong
- Ping pong
- ping-pong
- Ping pong
- Codeforces 319E Ping-Pong (线段树+dsu)
- hdu Ping pong Ping pong 线段树
- Playing ping-pong
- HDU 2492 Ping pong
- 3D - AVS 里面的一些变量缩写
- Heritrix eclipse创建java可运行程序的步骤
- python比较运算符连用问题(双等号连用)
- python -- pywin32安装
- Java回调函数
- Codeforces 320B Ping-Pong (Easy Version)
- 查看表空间碎片量
- Spark1.0.0 运行架构基本概念
- 代码片段
- php的安装在centos上
- GDB常用命令
- Android开发中的一些坑
- CSDN学院新功能:你关心的片头片尾、批量上传功能新鲜出炉了!——大白暖心呈现
- win7 搜索文件内容