原题链接: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. Eclipse阿里代码规范插件安装,卸载与使用

    使用阿里代码规范插件,我们就可以查看我们写的代码是否规范了 找到阿里代码插件网址: 网址:https://p3c.alibaba.com/plugin/eclipse/update/ 打开我们的网址, ...

  2. xshell和Xftp连接虚拟机(转载)

    首先连接虚拟机之前,先配置自己的IP地址,见博客https://www.cnblogs.com/xuzhaoyang/p/11264573.html xshell和Xftp下载请到官网http://w ...

  3. springmvc项目 logback.xml配置 logstash日志收集

    配置logback,需要一个转接的Appender,可以通过Maven依赖加到项目中: <dependency> <groupId>com.cwbase</groupId ...

  4. 如何在ubuntu下重建被grub覆盖的win10引导区?

    如何在ubuntu下重建被grub覆盖的win10引导区? 1.修改grub配置文件: sudo vi /etc/default/grub 2.设置:GRUB_DEFAULT = 2 3.更新配置文件 ...

  5. Java学习笔记-对象与垃圾回收

    Java存在垃圾回收机制,JVM会去回收垃圾,释放资源,而不是像C++一样有程序员去完成 垃圾回收机制的特点 垃圾回收机制只负责回收堆内存中的对象,不会回收任何物理资源(例如数据库连接.网络IO等资源 ...

  6. sql server新旧数据库的表结构差异

    sql server编写通用脚本自动检查两个不同服务器的新旧数据库的表结构差异 问题:工作过程中,不管是什么项目,伴随着项目不断升级版本,对应的项目数据库业务版本也不断升级,数据库出现新增表.修改表. ...

  7. spring使用FactoryBean给ioc容器加入组件

    FactoryBean是srping的一个接口,现在我们来创建一个类MyFactoryBean 来实现FactoryBean接口 package org.springframework.beans.f ...

  8. LOJ #10131 「一本通 4.4 例 2」暗的连锁

    LOJ #10131 「一本通 4.4 例 2」暗的连锁 给一棵 \(n\) 个点的树加上 \(m\) 条非树边 , 现在需要断开一条树边和一条非树边使得图不连通 , 求方案数 . $n \le 10 ...

  9. 如何查看class文件的编译jdk版本号

    使用命令 javap -verbose 命 进入cmd中,使用如下命令 红色

  10. codeforces 1244E Minimizing Difference (贪心)

    (点击此处查看原题) 题意分析 给出n个数,a1,a2...an,现在可以进行最多k次操作,每次操纵可以使得任意一个数自增或者自减,问经过最多k次操作后,n个数中的最大值-最小值最小为多少? 解题思路 ...