原题链接:http://codeforces.com/problemset/problem/320/B

之前自己做的时候一直读不懂题意,看了大佬的博客才知道是用dfs写,一道暴力搜索大水题https://www.cnblogs.com/windysai/p/3531473.html

题目意思:有两种操作:"1 x y"  (x < y) 和 "2 a b" (a ≠ b) 。 问对于的"2 a b" 询问,能否从第a行的区间到达第b行的区间(行的数量是以:"1 x y" 来统计的,不包括"2 a b"这些行),当然可以直达,也可以借助某些区间间接到达。假设给定一个区间为 (a, b) ,能到达区间 (c, d) 的条件需要满足 c < a < d 或者c < b < d 。以题目中的数据为例,

5

1 1 5

1 5 11

2 1 2

1 2 9

2 1 2

对于第3行的 2  1  2,即问从第1行:1  1  5 是否可以到达第2行的 1  5  11,这明显是不能的,因为 5 < 1 < 11 和 5 < 5 < 11 都不满足。而第5行的 2  1  2 则是可以的,因为可以借助1  2  9 这个桥梁:(1  5) ——> (2  9) ——> (5  11)。理由是 2 < 5  < 9 和  5 < 9 < 11。

#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm> using namespace std;
int n;
typedef pair<long long ,long long> PII;
PII p[];
int cun=; int v[];
bool check(int x,int y)
{
return((p[x].first < p[y].second && p[x].first > p[y].first) || (p[x].second < p[y].second && p[x].second > p[y].first));
}
void dfs(int x)
{
if(v[x])return;
v[x]=;
for(int i=;i<cun;i++)
{
if(check(x,i))
{
dfs(i);
}
}
return ;
}
int main()
{
cin >> n;
while(n--)
{
int a,b,c;
cin >> a >> b >>c;
if(a==)
{
p[cun].first = b;
p[cun].second=c;
cun++;
}
else if(a==)
{
memset(v,,sizeof(v));
dfs(b-);
if(v[c-])
{
cout <<"YES"<<endl;
}
else
{
cout <<"NO"<<endl;
}
} }
return ;
}

你的脸上风淡云轻,谁也不知道你的牙咬得有多紧。你走路带着风,谁也不知道你膝盖上仍有曾摔过的伤的淤青。你笑得没心没肺,没人知道你哭起来只能无声落泪。要让人觉得毫不费力,只能背后极其努力。我们没有改变不了的未来,只有不想改变的过去。

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

  1. C1. Pokémon Army (easy version) 解析(DP)

    Codeforce 1420 C1. Pokémon Army (easy version) 解析(DP) 今天我們來看看CF1420C1 題目連結 題目 對於一個數列\(a\),選若干個數字,求al ...

  2. HDU 2492 Ping pong (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Ping pong Problem Description N(3<=N<=2000 ...

  3. UVALive 4329 Ping pong

                                      Ping pong Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Fo ...

  4. Ping-Pong (Easy Version)(DFS)

    B. Ping-Pong (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. ZOJ 3868 - Earthstone: Easy Version

    3868 - Earthstone: Easy Version Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld ...

  6. POJ 3928 Ping pong(树状数组)

                                                                          Ping pong Time Limit: 1000MS   ...

  7. LA4329 Ping pong(树状数组与组合原理)

    N (3N20000)ping pong players live along a west-east street(consider the street as a line segment). E ...

  8. Ping pong

    Ping pong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. POJ 3928 Ping pong

    题目链接:http://poj.org/problem?id=3928 乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...

随机推荐

  1. Leetcode之并查集专题-765. 情侣牵手(Couples Holding Hands)

    Leetcode之并查集专题-765. 情侣牵手(Couples Holding Hands) N 对情侣坐在连续排列的 2N 个座位上,想要牵到对方的手. 计算最少交换座位的次数,以便每对情侣可以并 ...

  2. Eureka 分析记录

    本文是一些记录和想方法,分析大部分来自 http://www.iocoder.cn/Eureka/ 感兴趣的可以去看一下.

  3. 一次记录 java非web项目部署到linux

    1.生成可执行jar 运行提示没有主清单属性 一番查找原因:是因为将项目生成jar包的时候,生成的MANIFEST.MF没有MAIN-CLASS,这里加上就可以了,后面的是项目启动类的完整类名 当然还 ...

  4. mui ajax传参示例

    //加入购物车var data=[];var row1 = {good_id:'1',number:'2',goods_spec_ids:[1,2]};data.push(row1);console. ...

  5. poj1426(暴力dfs)

    题目链接:https://vjudge.net/problem/POJ-1426 题意:给出n(1<=n<=200),求出全部由01组成的能整除n的正整数. 思路:此题在unsigned ...

  6. 2019icpc-徐州网络赛

    B. hxc写的 AC code: #pragma GCC optimize(2) #include <cstdio> #include <queue> #include &l ...

  7. python的logging的配置

    在python项目中,开发环境是windows环境,发布环境是linux系统. import logging import logging.handlers import platform impor ...

  8. Redis 学习笔记(篇十):Sentinel

    Sentinel(哨兵)是 Redis 的高可用解决方案:由一个或多个 Sentinel 实例组成的 Sentinel 系统可以监视任意多个主服务器,以及这些主服务器属下的所有从服务器,并在被监视的主 ...

  9. 数据分析—win7+ipython+notebook安装

    先安装python 3.x 然后 cmd 执行 pip3 ipython 然后 cmd 执行 pip3 install jupyter notebook 然后 cmd 执行 jupyter noteb ...

  10. gitlab安装指南(gitlab-ce-9.4.3-ce.0.el7.x86_64 centos7)

    1,安装gitlab wget https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-9.4.3-ce.0.el7. ...