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和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...
随机推荐
- ORA-00054:Orcacle表锁定
查询被锁的session_id select session_id from v$locked_object; 查询结果----------------------SESSION_ID8 查询被锁se ...
- 最新 斗鱼java校招面经 (含整理过的面试题大全)
从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.斗鱼等10家互联网公司的校招Offer,因为某些自身原因最终选择了斗鱼.6.7月主要是做系统复习.项目复盘.LeetCode ...
- 巧用 Class Extension 隐藏属性
一般来说,Extension用来给Class增加私有属性和方法,写在 Class 的.m文件.但是Extension不是必须要写在.m文件,你可以写在任何地方,只要在 @implementation ...
- rabbitmq启动方式
1.以应用方式启动 rabbitmq-server -detached 后台启动 Rabbitmq-server 直接启动,如果你关闭窗口或者需要在改窗口使用其他命令时应用就会停止 关闭:rabbi ...
- Beta冲刺博客
这个作业属于哪个课程 当然是属于程序分析与设计呀 这个作业要求在哪里 在这儿 团队名称 六扇门编程小组(团队博客) 这个作业的目标 完成为期两周的β版本冲刺 1.团队信息 姓名 学号 曹欢(组长) 2 ...
- Feign 接口上传文件
1)Encoder 配置注入容器 2) public class SpringFormEncoderExtension extends FormEncoder { /** * 使用默认的feign编码 ...
- 如何判断你的windows系统是32位还是64位?
[学习笔记] 如 何判断你的windows系统是32位还是64位? java -version时,如果没有64就是32位的.eclipse.ini中如果没有64,就是32位的.但是我们的ini文件里面 ...
- C++ Primer 5th Chap1.Getting Started
在CommandPrompt上:(即cmd) 假定文件名为prog1.cc: 编译:$Compiler'sName prog1.cc 打开(prog1.exe):$prog1 打开(在当前目录):$. ...
- 封装PHP增删改查方法
<?php class sqlModel{ public $db; public function __construct(){ try{ $dbms='mysql';//数据库类型 $dbNa ...
- selenium模块基础用法详解
目录 selenium模块 官方文档 介绍 安装 有界面浏览器 无界浏览器 selenium+谷歌浏览器headless模式 基本使用 选择器 基本用法 xpath 获取标签属性 等待元素被加载 隐式 ...