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和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...
随机推荐
- 2019年9月Leetcode每日训练日志
2019-09-16 #1171 从链表中删去总和值为零的连续节点 #1170 比较字符串最小字母出现频次 #1169 查询无效交易 #226 翻转二叉树 2019-09-15 #1190 反转每对括 ...
- 「JOISC 2019 Day3」穿越时空 Bitaro
「JOISC 2019 Day3」穿越时空 Bitaro 题解: 不会处理时间流逝,我去看了一眼题解的图,最重要的转换就是把(X,Y)改成(X,Y-X)这样就不会斜着走了. 问题变成二维平面上 ...
- TensorFlow 官方文档 Programmer's Guide 中文翻译 —— 引言
TensorFlow Programmer's Guide (Introduction) TensorFlow 编程手册 (引言) #(本项目对tensorflow官网上给出的指导手册(TF1.3版本 ...
- GitHub克隆下载代码速度慢解决办法
这几天克隆下载GitHub代码奇慢无比,网上搜索了一下解决方案有些不太完整,自己试验出了比较完整的解决方式: 1.在hosts文件里追加以下内容(IP需要替换掉),以下几个域名一个都不要少,有些文章只 ...
- # win10下设置软件启动快捷方式
win10下设置软件启动快捷方式 win10下设置软件启动快捷键,必须把快捷方式放在C:\ProgramData\Microsoft\Windows\Start Menu\Programs目录下,在这 ...
- Photon Server 实现注册与登录(一) --- Hibernate整合到项目中
本系列实现目的:基于Photon Server实现注册于登录 一.拷贝Nbibernate项目的文件到MyGamerServer项目中. 二.数据库新建表,结构如下 三.修改文件名和配置 (1).将拷 ...
- php操作string的函数
函数库来源于:http://www.w3school.com.cn/php/php_ref_string.asp 我常用的 echo()------------输出一个或多个字符串. 如:echo ' ...
- 怎样查看Redis的版本号
Q: 怎样查看Redis版本 A: 下面两条命令都可以查看redis 版本: redis-server --version redis-server -v
- hdu 6045 多校签到题目
http://acm.hdu.edu.cn/showproblem.php?pid=6045 题解:遍历一遍,求出两个人答案中相同的个数,用wa表示.然后我从大的数入手,当wa的数都尽可能在两个人答案 ...
- ASP.NET-A low-level Look at the ASP.NE
请求处理模型1: ******** 1.浏览器向服务器发送请求,先到达服务器的http.sys系统文件,进行初步的处理. (服务器分为内核模式和用户模式,http.sys在内核模式种,IIS在用户模式 ...