Ping-Pong (Easy Version)的解析
原题链接: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)的解析的更多相关文章
- C1. Pokémon Army (easy version) 解析(DP)
Codeforce 1420 C1. Pokémon Army (easy version) 解析(DP) 今天我們來看看CF1420C1 題目連結 題目 對於一個數列\(a\),選若干個數字,求al ...
- HDU 2492 Ping pong (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Ping pong Problem Description N(3<=N<=2000 ...
- UVALive 4329 Ping pong
Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Fo ...
- Ping-Pong (Easy Version)(DFS)
B. Ping-Pong (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input ...
- ZOJ 3868 - Earthstone: Easy Version
3868 - Earthstone: Easy Version Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld ...
- POJ 3928 Ping pong(树状数组)
Ping pong Time Limit: 1000MS ...
- LA4329 Ping pong(树状数组与组合原理)
N (3N20000)ping pong players live along a west-east street(consider the street as a line segment). E ...
- Ping pong
Ping pong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- POJ 3928 Ping pong
题目链接:http://poj.org/problem?id=3928 乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...
随机推荐
- QFramework 使用指南 2020(五):脚本生成(3)生成 Prefab
在上一篇,我们简单介绍了 ViewController 的嵌套实现. 在这一篇,我们学习 ViewController 脚本生成的最后一个功能,即:生成 Prefab. 实际上这个功能非常简单. 我们 ...
- linux系统,CentOs7加新硬盘
1,打开Vmware软件,添加一块新的硬盘,然后一直下一步. 2.通过CRT等终端软件,连接到机器 [root@Mysql ~]# lsblk //检查一下硬盘分区信息 [root@Mysql ...
- jq append添加的元素click获取不到的解决方法
移动端手机ios网页,apppend添加html class名用 on()方法没效果 解决方案:在html里面给需要点击的元素加一个onclick="javascript:void(0)&q ...
- C/C++编程
基本的数据类型: 整型 浮点型(单精度.双精度) 在c语言中,所有的变量声明必须在任何执行语句之前(对当前域来说), 否则编译的时候会出现变量是未声明的标识符的错误. main 入口参数:argc 和 ...
- 【ARM-Linux开发】Linux链接
链接有两种方式:硬链接和软链接. (一)软链接 软链接又叫做符号链接.基本命令为: [plain] view plain copy ln -s sourcePlace newPlace 软链接可以链接 ...
- 【并行计算-CUDA开发】 NVIDIA Jetson TX1
概述 NVIDIA Jetson TX1是计算机视觉系统的SoM(system-on-module)解决方案.它组合了最新的NVIDIAMaxwell GPU架构,其具有ARM Cortex-A57 ...
- 【编程开发】C语言中随机数rand使用注意事项
[编程开发]C语言中随机数rand使用注意事项 标签: [编程开发] 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ 说明:随机数在编程开发中非常重要,以C语 ...
- Odoo 13 released..
origin https://medium.com/@jc_57445/odoo-13-is-fantastic-f2b421696b49 Most striking changes The most ...
- Android netty客户端入门
新建项目,加入netty库 implementation 'io.netty:netty-all:4.1.36.Final'
- P5441 【XR-2】伤痕
Luogu5441 有 \(n\) 个点 ( \(n\) 为奇数 , \(n \le 99\) ) 的完全图 , 其中可以有最多 \(n\) 条无向边 , 其他都是有向边 . 如果对于某四个点不经过这 ...