B. Ping-Pong (Easy Version)
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so that we can reach I2.

Your program should handle the queries of the following two types:

  1. "1 x y" (x < y) — add the new interval (x, y) to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals.
  • "2 a b" (a ≠ b) — answer the question: is there a path from a-th (one-based) added interval to b-th (one-based) added interval?

Answer all the queries. Note, that initially you have an empty set of intervals.

Input

The first line of the input contains integer n denoting the number of queries, (1 ≤ n ≤ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.

It's guaranteed that all queries are correct.

Output

For each query of the second type print "YES" or "NO" on a separate line depending on the answer.

近来很颓。。。

 #include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std; const int MAXN = ;
int a[MAXN], b[MAXN];
bool f[MAXN];
int n, cnt; void dfs(int s, int e)
{
f[s] = ;
if(f[e]) return ;
for(int i = ; i < cnt; i++)
{
if(f[i]) continue;
if(a[s] > a[i] && a[s] < b[i]) dfs(i, e);
if(f[e]) return ;
if(b[s] > a[i] && b[s] < b[i]) dfs(i, e);
if(f[e]) return ;
}
} int main()
{
while(scanf("%d", &n) != EOF)
{
cnt = ;
int m, x, y;
while(n--)
{
scanf("%d", &m);
if(m == )
{
scanf("%d %d", &a[cnt], &b[cnt]);
cnt++;
}
else
{
scanf("%d %d", &x, &y);
memset(f, , sizeof(f));
dfs(x, y);
if(f[y]) puts("YES");
else puts("NO");
}
}
}
return ;
}

Ping-Pong (Easy Version)(DFS)的更多相关文章

  1. Saving James Bond - Easy Version (MOOC)

    06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...

  2. Codeforces 1077F1 Pictures with Kittens (easy version)(DP)

    题目链接:Pictures with Kittens (easy version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:$dp[i][j ...

  3. E1. String Coloring (easy version)(贪心)

    E1. String Coloring (easy version) time limit per test 1 second memory limit per test 256 megabytes ...

  4. [ACM] POJ 3740 Easy Finding (DFS)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16202   Accepted: 4349 Description Give ...

  5. Codeforces Global Round 7 D1. Prefix-Suffix Palindrome (Easy version)(字符串)

    题意: 取一字符串不相交的前缀和后缀(可为空)构成最长回文串. 思路: 先从两边取对称的前后缀,之后再取余下字符串较长的回文前缀或后缀. #include <bits/stdc++.h> ...

  6. E1. Array and Segments (Easy version)(暴力) && E2. Array and Segments (Hard version)(线段树维护)

    题目链接: E1:http://codeforces.com/contest/1108/problem/E1 E2:http://codeforces.com/contest/1108/problem ...

  7. LeetCode Subsets II (DFS)

    题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...

  8. LeetCode Subsets (DFS)

    题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...

  9. HDU 2553 N皇后问题(dfs)

    N皇后问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 在 ...

随机推荐

  1. C#与数据库访问技术总结(八)之ExecuteNonQuery方法

    ExecuteNonQuery方法 ExecuteNonQuery方法主要用来更新数据. 通常使用它来执行Update.Insert和Delete语句. 该方法返回值意义如下: 对于Update.In ...

  2. iOS Runtime原理及使用

    runtime简介 因为Objc是一门动态语言,所以它总是想办法把一些决定工作从编译连接推迟到运行时.也就是说只有编译器是不够的,还需要一个运行时系统 (runtime system) 来执行编译后的 ...

  3. IMP-00038:无法转换为环境字符集句柄

    参考解决方案:http://www.cnblogs.com/wangsaiming/p/4947151.html

  4. js 导出Excel

    最近从Silverlight这边转到javascript过来,现在要导出一个导出excel的功能.上级领导指示当页显示多少数据,就导出多少数据,没有必要从后台在去数据.以前也没有接触过这方面的,在网上 ...

  5. SQL Server 内存中OLTP内部机制概述(二)

    ----------------------------我是分割线------------------------------- 本文翻译自微软白皮书<SQL Server In-Memory ...

  6. C++类的底层机理

    我们首先从一个问题来阐明类的底层机理: 假如有一个类A,里面有一个成员函数get(),例如: class A { public:     void get(); } A a; 那么a.get()表示什 ...

  7. Cluster群集

    Cluster群集一般来讲有四个功能1. 冗余功能,就是说在这个群集中的任何一台机器出现本机或网络故障时,整个网络仍不中断,对外的服务也不中断,网络有多个路线可以走,服务器也可以相互代替.2.负载均衡 ...

  8. Windows7给C盘扩容

    // 在之前的系统中都是使用PartitionMagic来进行磁盘容量的分配,但PartitionMagic在Windows7中的兼容性不是好很好,导致不能使用.其实Windows7自带了磁盘管理工具 ...

  9. Win7下VS2010使用“ASP.Net 3.5 Claims-aware Template”创建ClaimsAwareWebSite报"HRESULT: 0x80041FEB"错误的解决办法

    问题描述: 使用VS2010的WIF开发模板创建“Claims-aware ASP.NET Site”.“Claims-aware WCF Service”,下载安装后,创建网站时,报错"H ...

  10. 使用Android Studio打Andorid apk包的流程

    启动Android studio   1.点击菜单栏Build -> Generate Signed APK...,打开如下窗口 2.这里是类似eclipse中Android的签名,假设这里没有 ...